SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: simple array

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple array

    hi
    i have a simple array with 100 elements, but i need to use only the last 99 elements( without element[0] )

    how can I do without iterating through the array from 1 to 100, using a for? do you have any smarter solution?

  2. #2
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://uk.php.net/manual/en/function.array-shift.php

    $in = array(1,2,3,4, ..., 100);
    $out = array_shift($in);

    for ($i = 0; $i < count($out); $i++)
    {
    ....
    }
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MANY THX.....this is really a smart thing

  4. #4
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even simpler, you could use array_slice() to take a copy of the part of the array you want, and iterate through that:

    http://us.php.net/array_slice


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
  •