Passing by Reference with PHP and Javascript

PHP (test)

<?php

  function test(&$b) { // Passing by reference
   $b = array(4,5,6); // New Array
  }

  $a = array(1,2,3);

  print_r($a); // 1, 2, 3
  test($a);
  print_r($a); // 4, 5, 6

?>
      

Javascript (test)

(function() {

  function test1(b) { // Passing by reference
   b = [4, 5, 6];
  }

  function test2(b) {
   b.push(4);
  }

  var a = [1, 2, 3]; 

  alert(a); // 1, 2, 3
  test1(a);
  alert(a); // 1, 2, 3
  test2(a);
  alert(a); // 1, 2, 3, 4

})();
      

Passing by Reference with PHP and Javascript - pmav.eu 2009