Change an associative array into an indexed array / get an Zend_Table_Row_Abstract as non-associative

大憨熊 提交于 2019-12-02 23:15:48
Ian Elliott

Is pure php ok?

$array = array_values($array);

Source

define function

function array_default_key($array) {
    $arrayTemp = array();
    $i = 0;
    foreach ($array as $key => $val) {
        $arrayTemp[$i] = $val;
        $i++;
    }
    return $arrayTemp;
}

Pass the associative array as a parameter and it will convert into the default index of the array. For example: we have Array('2014-04-30'=>43,'2014-04-29'=>41) after the call to the function the array will be Array(0=>43,1=>41).

You could use this simple piece of code, if you do not want to use the inbuilt PHP function.

$input_array;           // This is your input array
$output_array = [];     // This is where your output will be stored.
foreach ($input_array as $k => $v){
    array_push($output_array, $v);
}
print_r($output_array);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!