Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to retrieve a string name as an array variable?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

thanks for helping me out.

>Solution :

You need to replace :

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

by :

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

Globally : change () by {}.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading