Dynamically transform simple array to multidimensional array in PHP -




i have array contry list this

$array = array('country1' => countryone, 'country2' => country two); 

how can dynamically transform array in multiple array like:

array(2) { [0] => array(2) { ["code"] => "country1",["name"] => "countryone"} [1] => array(2) { ["code"] => "country2",["name"] => "countrytwo"} }} 

simply loop through , create new array each key/value pair.

<?php     $array = array("country1" => "countryone", "country2" => "countrytwo");      $newarray = array();      foreach($array $key => $value) {         array_push($newarray, array("code" => $key, "name" => $value));     }      var_dump($newarray); ?> 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -