SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick QU on array_pop & array_shift

    Hi,

    Just wondering if anyone can tell me exactly how array 'pop and shift' work.

    If I have

    $Array[0] = 0;
    $Array[1] = 1;
    $Array[2] = 2;

    And then do:

    array_shift($Array);
    array_pop($Array);

    Are $Array[0] & $Array[2] destroyed leaving just $Array[1] ??

    or does $Array[1] become $Array[0]

    I'm slightly confused.

    Thanks

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. If array is empty (or is not an array), NULL will be returned."

    So the first array_shift will make the array be:
    $array[0] = 1;
    $array[1] = 2;

    And the array_pop will take out $array[1] = 2;

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


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
  •