滤镜阵列 - 奇偶 [英] Filter array - odd even
本文介绍了滤镜阵列 - 奇偶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何能过滤掉的数组项与奇数或偶数索引号?
How can a filter out the array entries with an odd or even index number?
Array
(
[0] => string1
[1] => string2
[2] => string3
[3] => string4
)
喜欢,我希望它从数组删除[0]和[2]项。
或者说,我有0,1,2,3,4,5,6,7,8,9 - 我需要删除0,2,4,6,8
Like, i want it remove the [0] and [2] entries from the array. Or say i have 0,1,2,3,4,5,6,7,8,9 - i would need to remove 0,2,4,6,8.
推荐答案
的foreach($改编为$关键=> $ value)如果($键和放大器; 1)未设置($改编[$关键]);
以上删除该数组奇数位置,删除偶数位置,使用以下命令:
The above removes odd number positions from the array, to remove even number positions, use the following:
而不是如果($键和放大器; 1)
您可以使用 IF(($键和放大器;!1))
这篇关于滤镜阵列 - 奇偶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文