3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 7867867, 'lock' => 0, 'score' => 322, 'strtotime' => 16614713], ['id' => 7867867, 'lock' => 0, 'score' => 444, 'strtotime' => 16614613], ['id' => 7867867, 'lock' => 3, 'score' => 0, 'strtotime' => 16613713], ['id' => 7867867, 'lock' => 0, 'score' => 11, 'strtotime' => 16612713], ['id' => 7867867, 'lock' => 5, 'score' => 0, 'strtotime' => 16614413], ['id' => 7867867, 'lock' => 0, 'score' => 42, 'strtotime' => 16614113], ['id' => 7867867, 'lock' => 0, 'score' => 22, 'strtotime' => 16614013], ]; $maxIndex = count($array) - 1; for ($a = 0; $a < $maxIndex; ++$a) { if ($array[$a]['lock'] !== 0) { continue; // cannot move locked row } for ($b = 0; $b < $maxIndex; ++$b) { if ($array[$b]['lock'] !== 0) { continue; // cannot move locked row } // find next movable row for ($c = $b + 1; $c <= $maxIndex; ++$c) { if ($array[$c]['lock'] === 0) { break; // $c is index of non-locked row } } if ($c > $maxIndex) { break; // no more movable rows } // sort movable rows if ( $array[$b]['score'] > $array[$c]['score'] || ($array[$b]['score'] === $array[$c]['score'] && $array[$b]['strtotime'] > $array[$c]['strtotime']) ) { [$array[$b], $array[$c]] = [$array[$c], $array[$b]]; } } } var_export($array);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'id' => 7867867, 'lock' => 0, 'score' => 11, 'strtotime' => 16612713, ), 1 => array ( 'id' => 7867867, 'lock' => 0, 'score' => 22, 'strtotime' => 16614013, ), 2 => array ( 'id' => 7867867, 'lock' => 3, 'score' => 0, 'strtotime' => 16613713, ), 3 => array ( 'id' => 7867867, 'lock' => 0, 'score' => 42, 'strtotime' => 16614113, ), 4 => array ( 'id' => 7867867, 'lock' => 5, 'score' => 0, 'strtotime' => 16614413, ), 5 => array ( 'id' => 7867867, 'lock' => 0, 'score' => 322, 'strtotime' => 16614713, ), 6 => array ( 'id' => 7867867, 'lock' => 0, 'score' => 444, 'strtotime' => 16614613, ), )

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:
79.47 ms | 407 KiB | 5 Q