Thursday, 31 August 2017

PHP variables to array

I often see or have to convert a bunch of variables into an array like this:



$array = array("description"=>$description, "title"=>$title, "page"=>$page, "author"=>$author);


Basically, all array keys match the name of the variable that is being passed in. Is there a way to reference a variable name so that it can be passed into the array like so:



$array[varName($description)] = $description;

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...