Peter Agger
Peter Agger

Reputation: 63

odd and even to line

i have array:

$array = ('aaa', 4, 'fff', 2, 'ddd', 3, 'ddd', 32, '3243', 34, 'sdfs', 3);

i woulde like make this:

  ['aaa', 4],
  ['fff', 24],
  ['ddd', 3],
  ['ddd', 32],
  ['3243', 34]
  ['sdfs', 3]

foreach($array as $i => $a){
    //????
}

how is the method for this with PHP?

Upvotes: 0

Views: 73

Answers (1)

Andreas Wong
Andreas Wong

Reputation: 60536

array_chunk($array, 2);

http://php.net/manual/en/function.array-chunk.php

Upvotes: 4

Related Questions