I am trying to dynamically generate a string n then use it inside list() to catch array values in variables.
Code :
<?php
$bubba = "value1, value2, value3, value4, value5, value6, value7";
$hubba = explode(",", $bubba);
$num = count($hubba);
ob_start();
for($i=1; $i<=$num; $i++){
echo ('$k'.$i.', ');
}
$varname = ob_get_clean();
$varname = substr($varname, 0, -2);
list(echo $varname;) = $hubba;
I want this to look like:
list($k1, $k2, $k3, $k4, $k5, $k6, $k7) = $hubba;
echo $k1; // must echo value1
?>
But, list simply is not-ready to accept the variable string. How to do this ?
list()call you might get better results."value1, value2, value3, value4, value5, value6, value7"and what do you want it to look like or how do you need to use it.