How to use compact() function to create array from variables and their values in PHP

1 Answer

0 votes
$city  = "California US";
$state = "Los Angeles";
$company = "Soft Pro Experts";
   
$arr = compact("city", "state", "company");
print_r($arr);


/*
run:

Array ( [city] => California US [state] => Los Angeles [company] => Soft Pro Experts ) 
   
*/

 



answered Mar 8, 2016 by avibootz
...