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
Post a Comment