2

Array is like..

array ( 
      [0] => a
      [1] => b
      [2] => c
      [3] => d
      [4] => e
      [5] => f
      [6] => g
      [7] => h
     )

I want pair them like..

Array 
( [0] => Array ( 
    [0] => a
    [1] => b)

  [1] => Array ( 
    [0] => c
    [1] => d) 

  [2] => Array ( 
    [0] => e
    [1] => f)

  [3] => Array ( 
    [0] => g
    [1] => h)
)

How can i do this? there are 8 values and I want 4 pairs from these 8 values. I am new to php so I don't really knw much about php and I searched google but can't find a solution for this.

4

1 回答 1

7

您可以使用array_chunk()

print_r(array_chunk($arr, 2));

演示

于 2013-04-24T06:20:47.640 回答