php - How to reformatted array -


i have array indexes like

$array = array(     "first_name" => "test",     "last_name" => "testsurename" ); 

i need convert to:

$array = array(     "0" => array("first_name" => "test"),     "1" => array("last_name" => "testsurename") ); 

try this,

$array = array("first_name"=>"test","last_name"=>"testsurename"); $newarray = array(); foreach($array $key=> $val) {     $newarray[][$key] = $val; } print_r($newarray); 

output :

$array = array(     "0" => array("first_name" => "test"),     "1" => array("last_name" => "testsurename") ); 

demo


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -