fork(4) download
  1. <?php
  2. echo "Filling the array... ";
  3. $t=time();
  4. $a=array();
  5. for($i=0;$i<10000;$i++) $a[uniqid()]=rand(0,100);
  6. $t=time()-$t;
  7. echo "$t sec\n";
  8.  
  9. function get_my_array()
  10. {
  11. global $a;
  12. return $a;
  13. }
  14.  
  15. echo "Using reset():";
  16. $t=microtime(true);
  17. echo reset(get_my_array());
  18. $t=microtime(true)-$t;
  19. echo " ($t sec)\n";
  20.  
  21. echo "Using array_values():";
  22. $t=microtime(true);
  23. echo array_values(get_my_array())[0];
  24. $t=microtime(true)-$t;
  25. echo " ($t sec)\n";
  26.  
Success #stdin #stdout 0.02s 20816KB
stdin
Standard input is empty
stdout
Filling the array... 11 sec
Using reset():6 (0.0050840377807617 sec)
Using array_values():6 (0.0041720867156982 sec)