我有一个关联数组,当var dumped看起来像这样:
- Array
- (
- [tumblr] => Array
- (
- [type] => tumblr
- [url] => http://tumblr.com/
- )
- [twitter] => Array
- (
- [type] => twitter
- [url] => https://twitter.com/
- )
- )
正如您所看到的,键是自定义“tumblr”和“twitter”而不是数字0和1.
- (
- [type] => tumblr
- [url] => http://tumblr.com/
- )
您可以通过
array_values()
运行该阵列:
- $myarray = array_values( $myarray);
现在你的数组看起来像:
- array(2) {
- [0]=>
- array(2) {
- ["type"]=>
- string(6) "tumblr"
- ["url"]=>
- string(18) "http://tumblr.com/"
- } ...
这是因为array_values()只会从数组中获取值,并将数组重置/重新排序/重新键入为数字数组.