Passing arrays by reference : Variable Reference « Language Basics « PHP






Passing arrays by reference

 
<?
    function load_member_data($ID, &$member) {
            $member["Name"] = "Bob";
            return true;
    }

    $ID = 1;

    $result = load_member_data($ID, $member);

    if ($result) {
            print "Member {$member["Name"]} loaded successfully.\n";
    } else {
            print "Failed to load member #$ID.\n";
    }
?>
  
  








Related examples in the same category

1.$b is assigned a copy of $a, and in the second part, $b is assigned a reference to $a.
2.& operator creates a reference
3.Create a reference to a variable with the name of the constant's value.
4.Passing by Reference in PHP
5.Only named variables may be assigned by reference.