I’m having trouble splitting an array in two.
Array
(
[0] => livree
[1] => 2011-12-26
[2] => livree
[3] => 2011-12-27
[4] => livree
[5] => 2011-12-28
[6] => livree
[7] => 2011-12-29
[8] => livree
[9] => 2011-12-30
[10] => livree
[11] => 2011-12-31
[12] => livree
[13] => 2012-01-01
[14] => livree
[15] => 2012-01-02
[16] => livree
[17] => 2012-01-03
[18] => en_cours
[19] => 2012-01-04
[20] => en_cours
[21] => 2012-01-05
[22] => en_cours
[23] => 2012-01-06
[24] => en_cours
[25] => 2012-01-07
[26] => en_cours
[27] => 2012-01-08
)
I use those functions to detect odd/even key and split it in two differents array:
function odd($var){return($var & 1);}
function even($var){return(!($var & 1));}
$odd = array_filter($vb, "odd");
$even = array_filter($vb, "even");
I’m only having thoses two array:
Array
(
[0] => 2011-12-26
[1] => 2011-12-27
[2] => 2011-12-28
[3] => 2011-12-29
[4] => 2011-12-30
[5] => 2011-12-31
[6] => 2012-01-01
[7] => livree
[8] => livree
[9] => en_cours
[10] => en_cours
[11] => en_cours
[12] => en_cours
[13] => en_cours
)
Array
(
[0] => livree
[1] => livree
[2] => livree
[3] => livree
[4] => livree
[5] => livree
[6] => livree
[7] => 2012-01-02
[8] => 2012-01-03
[9] => 2012-01-04
[10] => 2012-01-05
[11] => 2012-01-06
[12] => 2012-01-07
[13] => 2012-01-08
)
What did I do wrong??? Thx for your help!
array_filterpasses you the value, not the key. I fail to understand why you are getting exactly these results, but anyway, you don’t need array_filter at all:Faster way to do it:
Cuter way to do it:
…and for some reason I also think you really wanted an associative array: