3v4l.org

run code in 300+ PHP versions simultaneously
<?php $amount = $qty = $code = $id = range(1, 5000); //dry-run $op = '%s executed in %.8f seconds'; $start = $end = microtime(true); $max = count($id); $data = []; for ($i=0; $i<ceil($max/2); $i++) { $z = $max-($i+1); $data[$i] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; $data[$z] = [ 'id' => $id[$z], 'code' => $code[$z], 'qty' => $qty[$z], 'amount' => $amount[$z] ]; } //end dry-run $start = microtime(true); $max = count($id); $half = ceil($max/2); $data = []; for ($i=0; $i<$half; $i++) { $z = $max-($i+1); $data[$i] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; $data[$z] = [ 'id' => $id[$z], 'code' => $code[$z], 'qty' => $qty[$z], 'amount' => $amount[$z] ]; } $end = microtime(true); printf($op, 'for ceil', $end - $start);

preferences:
32.69 ms | 407 KiB | 5 Q