使用关联子数组将关联数组转换为索引数组

I have a simple associative array with country data like this:

$array = array('country1' => CountryOne, 'country2' => Country Two);

How can I dynamically transform this array in a multiple array like:

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

Simply loop through it and create a new array from each key/value pair.

<?php
    $array = array("country1" => "CountryOne", "country2" => "CountryTwo");

    $newArray = array();

    foreach($array as $key => $value) {
        array_push($newArray, array("code" => $key, "name" => $value));
    }

    var_dump($newArray);
?>

This is simple do like this

$array = array( array('code'=> "country1", 'name'=> "CountryOne"), array('code'=> "country2", 'name'=> "CountryTwo"));

Simple. Iterate through your array and fill another with what you find in it :

$dst_array = array();
foreach ($array as $k => $v) {
    $dst_array[] = array('code' => $k, 'name' => $v);
}