Filter array - odd even

后端 未结 7 2057
别那么骄傲
别那么骄傲 2021-01-12 05:56

How can a filter out the array entries with an odd or even index number?

Array
(
    [0] => string1
    [1] => string2
    [2] => string3
    [3] =&         


        
7条回答
  •  伪装坚强ぢ
    2021-01-12 06:25

    Here's a "hax" solution:

    Use array_filter in combination with an "isodd" function.

    array_filter seems only to work on values, so you can first array_flip and then use array_filter.

    array_flip(array_filter(array_flip($data), create_function('$a','return $a%2;')))
    

提交回复
热议问题