fork download
  1. <?php
  2.  
  3. $rawitems = [['nope1' => 'a', 'nope2' => 'b'], ['nope1' => 'c', 'nope2' => 'd']];
  4. $itemskey = ['key1', 'key2'];
  5. foreach ($rawitems as $row) {
  6. $tmp = array_combine($itemskey, $row);
  7. $tmp['key2'] = [$tmp['key2']];
  8. $items[] = $tmp;
  9. }
  10.  
  11. print_r($items);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [key1] => a
            [key2] => Array
                (
                    [0] => b
                )

        )

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

        )

)