Home > other >  How to retrieve a string name as an array variable?
How to retrieve a string name as an array variable?

Time:11-27

I have a question about PHP string and array, I have an array called

$profile_name = array();
$str_profile_name = 'profile_name';

Now I want to call this array with the help of str_profile_name and push it every time inside a loop, which is like that array_push($($str_profile_name), $name);

but it give errors, $name is any string names, It doesn't matter, which matters is that I want to push $name string into the ($profile_name) array, but by using $str_profile_name.

thanks for helping me out.

CodePudding user response:

You need to replace :

array_push($($str_profile_name), $name);

by :

array_push(${$str_profile_name}, $name);

Globally : change () by {}.

  •  Tags:  
  • php
  • Related