<?php $id = [11,12,13]; $code = ['1234','5678','9012']; $qty = [3,4,5]; $amount = [12.34,23.45,34.56]; //dry-run $op = '%s executed in %.8f seconds'; $start = $end = 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 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);
You have javascript disabled. You will not be able to edit any code.