www.webdeveloper.com
Results 1 to 3 of 3

Thread: foreach code for implode count, help please

  1. #1
    Join Date
    May 2006
    Posts
    22

    foreach code for implode count, help please

    I need to return each number from 1 - 10000 individually

    to out each number as part of url to build the link.
    How to write out the the foreach syntax, please help

    Code:
    	$thumbnails = implode($thumbnails, range(1, 10000));

  2. #2
    Join Date
    Jul 2011
    Posts
    131
    You can use just
    PHP Code:
    foreach (range(010000) as $number) {
        echo 
    $number;

    see http://php.net/manual/en/function.range.php

  3. #3
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    You may want to avoid doing that, for example, in Python:

    Code:
    for x in xrange(1,1000):
    
    #is fast, but this:
    
    for x in xrange(1,1000000):
    
    #is incredibly slower
    because it's assigning all of the numbers ahead of time. I don't think this is much different in PHP, so consider writing it like this:

    PHP Code:
    for($i=1;$i<=1000;$i++) echo $i,"\n"
    Technically both ways work, but I think this one is preferable because you aren't assigning the array to any fixed variable to use later.

    Edit: What I'm trying to say, is that you should use a for loop here. I think it's more than a matter of style; it is an ideal construct for this job
    Last edited by eval(BadCode); 04-04-2012 at 06:27 PM.
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles