3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $items = array( array( 'forename' => 'Foo', 'surname' => 'Bar' ), array( 'forename' => 'Bar', 'surname' => 'Foo' ) ); $arr = array(); foreach($items as $item){ $arr['name'][] = $item['forename']; $arr['surname'][] = $item['surname']; } echo "<pre>".print_r($arr, true)."</pre>"; ?>
Output for 4.3.0 - 7.1.0
<pre>Array ( [name] => Array ( [0] => Foo [1] => Bar ) [surname] => Array ( [0] => Bar [1] => Foo ) ) </pre>