重建索引在PHP过滤后的数组? [英] Reindexing an array after filtering in php?

查看:115
本文介绍了重建索引在PHP过滤后的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我取消设置从我的阵列使用这一切的,甚至索引值:

 的foreach($改编为$关键=> $ value)如果(($键和放大器;!1))未设置($改编[$关键]);

当我使用打印阵列结构的print_r()我得到:

 阵列([1] =>名1 [3] =>名2)

如何过滤我的数组后重建索引所以结构将是:

 阵列([0] =>名1 [1] =>名2)


解决方案

使用 array_values​​()

  $ ARR = array_values​​($ ARR);

I unset all the even index values from my array using this:

foreach($arr as $key => $value) if(!($key&1)) unset($arr [$key]);

and when I print the array structure using print_r() I get:

Array ( [1] => name1 [3] => name2 ) 

How to reindexing after filtering my array so the structure would be:

Array ( [0] => name1 [1] => name2 ) 

解决方案

Use array_values()

$arr = array_values($arr);

这篇关于重建索引在PHP过滤后的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆