I have class for take values inside loop as this :
$db_user->take_phone[1];
Inside loop I need take different values for the class
$a=array("phone","name","street");
foreach($a as $aa) {
echo $db_user->take_'$aa.'[1]
}
As you can see inside the loop I need to change the value inside take_$string
, but it doesn’t work. I suppose there is a syntax error but I’m not sure. How can I write this to work correctly.
I’ve tried different ways but haven’t found a solution.
2
Answers
You can use a variable variable, which takes the form of
$var->$property
. Notice the extra$
.Demo: https://3v4l.org/HolHZ
You have errors php syntax. I has explained it in my example more: