1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php range display all except for last record

Discussion in 'PHP' started by xbat, Oct 6, 2014.

  1. #1
    I have a php range
    $first=1;
    $last=10;

    foreach(range($first,$last) as $number)
    {echo $number."\n";}

    which will display
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10


    What I am looking for is

    1
    2
    3
    4
    5
    6
    7
    8
    9

    Any suggestions on the most efficient way to do this? Also the numbers always change too. It may not be 9 there maybe 20 or 40, or 5. I was thinking somewhere along the lines of a -1 of some sort.
     
    Solved! View solution.
    xbat, Oct 6, 2014 IP
  2. #2
    like that?

    foreach(range($first,($last-1)) as $number)
    Code (markup):
     
    Anveto, Oct 6, 2014 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    phpina I did try the -1 but with out the () You are the man!!!

    Thank you so much!
     
    xbat, Oct 6, 2014 IP
  4. Jigney

    Jigney Active Member

    Messages:
    168
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    93
    #4
    In the foreach loop when you put range at that time you just have to decrease your range end,

    So you just have to put ($first,($last-1))

    Hope it works for you...
     
    Jigney, Oct 9, 2014 IP