test - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of test.php

  1. <?php
  2. $a = array(0,1,2,3,4,5);
  3. $b = array('test'=>'test','test2'=>'test2','test3'=>'test3','test4'=>'test4');
  4. $v = 0;
  5. $n = 1000000;
  6.  
  7.  
  8. $startTime = microtime(true);  
  9.  
  10. for ($i = 0; $i <= $n; $i++)
  11. {
  12.     $x = $v;
  13. }
  14. $endTime = microtime(true);  
  15. $elapsed = $endTime - $startTime;
  16. echo "Variable : $elapsed seconds".PHP_EOL;
  17.  
  18.  
  19. $startTime = microtime(true);  
  20. for ($i = 0; $i <= $n; $i++)
  21. {
  22.     $x = $a[1];
  23. }
  24. $endTime = microtime(true);  
  25. $elapsed = $endTime - $startTime;
  26. echo "Array: $elapsed seconds".PHP_EOL;
  27.  
  28.  
  29. $startTime = microtime(true);  
  30. for ($i = 0; $i <= $n; $i++)
  31. {
  32.     $x = $b['test3'];
  33. }
  34. $endTime = microtime(true);  
  35. $elapsed = $endTime - $startTime;
  36. echo "Array by string key: $elapsed seconds";
  37.  
File Description
  • test
  • PHP Code
  • 19 Feb-2018
  • 707 Bytes
You can Share it: