Guest User

Untitled

a guest
Jun 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. $a=1;
  2. function $test(){
  3. echo $a;
  4. }
  5.  
  6. //outputs 1
  7.  
  8. $test = array(
  9. 0=>'zero',
  10. 1=>'one',
  11. 2=>'two',
  12. 3=>'three',
  13. );
  14.  
  15. function doesntWork($something){
  16. echo "My favorite number is " . $test[$something];
  17. }
  18.  
  19. //outputs My favorite number is 0
  20.  
  21. <?php
  22. $a=1;
  23. function test($foo) {
  24. echo 'number ' . $foo;
  25. };
  26.  
  27. test($a);
  28. // -> "number 1".
  29. ?>
  30.  
  31. <?php
  32. $test = array(
  33. 0=>'zero',
  34. 1=>'one',
  35. 2=>'two',
  36. 3=>'three',
  37. );
  38.  
  39. function doesntWork($test, $something){
  40. echo "My favorite number is " . $test[$something];
  41. }
  42.  
  43. doesntWork($test, mt_rand(0,3));
  44. ?>
  45.  
  46. function test() {
  47. global $a;
  48. echo $a;
  49. }
  50.  
  51. function doesWork($something) {
  52. global $test;
  53. echo "My favorite number is " . $test[$something];
  54. }
Add Comment
Please, Sign In to add comment