Help with a Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dubs
Forum Commoner
Posts: 28
Joined: Tue Oct 12, 2004 4:55 pm

Help with a Function

Post 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 &
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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
Post Reply