PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jmut
Forum Regular
Posts: 945 Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:
Post
by jmut » Wed Aug 02, 2006 9:33 am
how could I determine if the first itteration of foreach.
I now how to determine if last...but first?
Code: Select all
//determine if in last itteration
foreach ($array as $elem) {
if (!next($array)) {
//this is last itteration. no more.
}
}
Of course I can add a variable or something. I would rather not use weird solutions.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 02, 2006 9:36 am
Code: Select all
$first = true;
foreach ($array as $elem)
{
if ($first)
{
// do something
$first = false;
}
}
jmut
Forum Regular
Posts: 945 Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:
Post
by jmut » Wed Aug 02, 2006 9:45 am
feyd wrote: Code: Select all
$first = true;
foreach ($array as $elem)
{
if ($first)
{
// do something
$first = false;
}
}
gr....ok I thought I don't need variable. But guess this is as perfect as it gets
10x
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Aug 02, 2006 9:51 am
feyd wrote: Code: Select all
$first = true;
foreach ($array as $elem)
{
if ($first)
{
// do something
$first = false;
}
}
I cannot believe that for three years this logic has evaded me. Damn, where have I been?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 02, 2006 9:53 am
Everah wrote: Damn, where have I been?
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Aug 02, 2006 10:24 am
Pimps smilies are going to be the end of me, I know it.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Aug 02, 2006 10:30 am
where the hell are you guys getting those?
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Aug 02, 2006 8:09 pm
The little yellow Walmart rejects are residing comfortably in a corner of Modville. Right next to the Oompa Loompas.