0

I have a variable $item='name'. I want to create a new variable called $nameError.

Because $item changes through each loop I would like to set this like: $$itemError however I know this syntax is incorrect.

Can anyone let me know the correct way to do this?

Ricky Barnett
  • 1,130
  • 3
  • 15
  • 32
  • You're probably looking for [variable variables](http://php.net/manual/en/language.variables.variable.php). For partial varvar names you'd use `${"{$item}Error"} = "...";` - What you actually *ought to be using* is an array however. – mario Aug 07 '15 at 10:10
  • @mario Just: `${$item . "Error"}` is enough :) – Rizier123 Aug 07 '15 at 10:24

0 Answers0