I am assigning an array with the $variables(have different name) that have some values like:
array($one, $two, $three);
now i am a searching a way that is there any way to assign this above array with key name same as variable name directly, finally i want to make this array like:
array(
"one" => $one,
"two" => $two,
"three" => $three
)
if this can possible at the time of assigning array with the variable then i would be good for me then i can easily extract() this array and i don't have to do operation to open this array and assigning these values with the $variable name, if any function() exist for that then it will be good, please help if any one knows
compact is the inverse of extract. Use it like this :
$array = compact ('one', 'two', 'three');
This will look for the variables named 'one', 'two', 'three', and does exactly what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With