Access dynamic variables by wrapping {}
brackets around, like this:
$var = ${'hello'.$i.'_world'};
If the value of $i
is “foo”, then $var
would actually be assigned to the value of $hellofoo_world
.
This can also be used in arrays (or objects generated from JSON data), like this:
$data = json_decode($output);
$var = $data->{'foo'.$i.'bar'};
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.