Quickest way to replace associative array keys with numerical keys

瘦欲@ 提交于 2019-12-22 09:45:56

问题


I have an array:

array('something' => 'like this', 'something' => 'like this', 'something' => 'like this');

I would like to replace it (quickly as possible, using a simple inline function) to be like this:

array(0 => 'like this', 1 => 'like this', 2 => 'like this');

Possible using any built-in php-array functions?


回答1:


check out array_values

$new_array=array_values($array);
print_r($new_array);



回答2:


$arr = array(
             'something'=>'something',
             'something'=>'something'
             );

$new_arr = array();
$new_arr = array_values(arr);

    print_r($new_arr);



回答3:


$arr = array(
    'something'=>'something',
    'something'=>'something'
);

sort($arr);

print_r($arr);


来源:https://stackoverflow.com/questions/6384761/quickest-way-to-replace-associative-array-keys-with-numerical-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!