SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    And Sign before foreach loop

    hi

    i got this code while googling on net
    Code:
     foreach ($_SESSION["cart_array"] as &$each_item) { 
                if ($each_item['item_id'] == $pid) {
                    $each_item['quantity'] += 1;
                    $wasFound = true;
                    break;
                }
    can someone tell me what does "&" sign before $each_item signifies

    what is the use of "&" sign before $each_item in foreach loop

    vineet

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    It's a reference: http://php.net/manual/en/language.references.php

    To see what it does, do a var_dump of $_SESSION["cart_array"] before and after the loop, and check for differences.

    And then do a similar loop with the &, do a var_dump of $_SESSION["cart_array"] before and after that loop, and check for differences.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •