3v4l.org

run code in 300+ PHP versions simultaneously
<?php $messages = array( 'message1'=>array( 'type'=>'voice', 'call-id'=>'11', 'id'=>'message1' ), 'message2'=>array( 'type'=>'voice', 'call-id'=>'44', 'id'=>'message2' ), 'message3'=>array( 'type'=>'text', 'call-id'=>'44', 'id'=>'message3' ), 'message4'=>array( 'type'=>'text', 'call-id'=>'55', 'id'=>'message4' ), 'message5'=>array( 'type'=>'voice', 'call-id'=>'55', 'id'=>'message5' ), ); foreach ($messages as $message => $value) { $unique[$value['call-id']] = $value; // this will override the previous value with the same key if exists } $unique = usort($unique, "cmp"); print_r($unique); foreach ($unique as $key => $value) { $array[$value['id']] = $value; } echo '<pre>'; print_r($array); function cmp($a, $b) { return $a["call-id"] - $b["call-id"]; }
Output for git.master, git.master_jit
1 Warning: foreach() argument must be of type array|object, bool given in /in/blfIJ on line 40 <pre> Warning: Undefined variable $array in /in/blfIJ on line 45
Output for rfc.property-hooks
1 Warning: foreach() argument must be of type array|object, true given in /in/blfIJ on line 40 <pre> Warning: Undefined variable $array in /in/blfIJ on line 45

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.84 ms | 401 KiB | 8 Q