How to call an array using a string in PHP -


i echo bunch of arrays in numerical order, tried using while method lacks knowledge on how combine strings call variable , value inside array.

$ins1 = array (                "select"  => array (                                      "1" => "1"                                    ),                "note"  => array (                                     "1" => "message"                                    )               );   $ins2 = array (                "select"  => array (                                      "1" => "2"                                    ),                "note"  => array (                                     "1" => "sorry"                                    )               );    $count = 1; while($count <= 2){     $ins = '$ins'.$count;     echo $ins["select"][$count] .' '. $ins["note"][$count].'<br>';     $count++; } 

output should be:

1 message 2 sorry 

what you're looking "variable variables", through can set variable name dynamically; want, change code following:

$count = 1; while($count <= 2){     $ins = 'ins'.$count;     $var = $$ins; // $var either $ins1 or $ins2 :)     echo $var["select"][1] .' '. $var["note"][1].'<br>';     $count++; } 

the output be:

1 message 2 sorry 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -