fork download
  1. <?php
  2. $arr = ['a','b','c'];
  3. $res = [];
  4. if(( $count = count($arr)) % 2) array_push( $arr, null);
  5. for ($i = 0; $i < $count; $i+=2) {
  6. $res[$arr[$i]] = $arr[$i+1];
  7. }
  8.  
  9. print_r($res);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [a] => b
    [c] => 
)