3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array( array('relatedOrderNumber' => 10641, 'relationtype' => 1007), array('relatedOrderNumber' => 82010, 'relationtype' => 1007), array('relatedOrderNumber' => 82020, 'relationtype' => 1007), array('relatedOrderNumber' => 82040, 'relationtype' => 1007), array('relatedOrderNumber' => 82040, 'relationtype' => 1013) ); $new = array_reduce( $array, function($carry, $item) { $type = $item['relationtype']; $orderNumber = $item['relatedOrderNumber']; if (!isset($carry[$type])) { $carry[$type] = [orderNumber]; } else { $carry[$type][] = orderNumber; } }, array() ); var_dump($new);
Output for 7.2.0
Warning: Use of undefined constant orderNumber - assumed 'orderNumber' (this will throw an Error in a future version of PHP) in /in/np688 on line 18 Warning: Use of undefined constant orderNumber - assumed 'orderNumber' (this will throw an Error in a future version of PHP) in /in/np688 on line 18 Warning: Use of undefined constant orderNumber - assumed 'orderNumber' (this will throw an Error in a future version of PHP) in /in/np688 on line 18 Warning: Use of undefined constant orderNumber - assumed 'orderNumber' (this will throw an Error in a future version of PHP) in /in/np688 on line 18 Warning: Use of undefined constant orderNumber - assumed 'orderNumber' (this will throw an Error in a future version of PHP) in /in/np688 on line 18 NULL
Output for 5.4.0 - 7.1.10
Notice: Use of undefined constant orderNumber - assumed 'orderNumber' in /in/np688 on line 18 Notice: Use of undefined constant orderNumber - assumed 'orderNumber' in /in/np688 on line 18 Notice: Use of undefined constant orderNumber - assumed 'orderNumber' in /in/np688 on line 18 Notice: Use of undefined constant orderNumber - assumed 'orderNumber' in /in/np688 on line 18 Notice: Use of undefined constant orderNumber - assumed 'orderNumber' in /in/np688 on line 18 NULL