functionTypes - 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 functionTypes.php

  1. <?php
  2. function copyValue(array $arr) {
  3.     $arr[] = 2;
  4. }
  5.  
  6. function returnValue(array $arr): array {
  7.     $arr[] = 3;
  8.     return $arr;
  9. }
  10.  
  11. function referenceValue(array &$arr) {
  12.     $arr[] = 4;
  13. }
  14.  
  15.  
  16. $array1 = [1];
  17.  
  18. copyValue($array1); //bleibt [1]
  19. $array1 = returnValue($array1); //wird [1,3]
  20. referenceValue($array1); //wird [1,3,4]
  21.  
  22. var_dump($array1);
File Description
  • functionTypes
  • PHP Code
  • 15 Sep-2019
  • 348 Bytes
You can Share it: