Page 1 of 1

Help with a Function

Posted: Wed Oct 13, 2004 7:15 am
by dubs
twigletmac | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

function &getProduct($name) {
    foreach ($_SESSION['cart'] as $key => $product) {
        if ($product[0] == $name) {
            return &$_SESSION['cart'][$key];
        }
    }
    return FALSE;
}
Could someone explain the reason why the function above begind with a & and also why $_SESSION[cart][$key] also begins with a &

Posted: Wed Oct 13, 2004 7:35 am
by kettle_drum
& is used to pass values by reference as opose to copying the value. By default all paramaters are passed by value and by adding a & to the function name you change this to making them pass by reference. For more info read the manual:

http://www.php.net/manual/en/functions.arguments.php