In a for loop it is simple...
for ( $idx = 0 ; $idx < count ( $array ) ; $idx ++ )
{
if ( $idx == 0 )
{
// This is the first element of the array.
}
}
How the hell is this done in a foreach loop?
is there a function like is_first() or something?
I'm looking for something like:
foreach ( $array as $key => $value )
{
if ( /* is the first element */ )
{
// do logic on first element
}
else
{
// all other logic
}
}
I was thinking I could set a bool like $is_first = true; and then as soon as the loops been iterated once, set the bool to false.
But php has a lot of pre-built functions and id rather use that... or another way...
The whole bool way seem almost like... cheeting :s
Cheers,
Alex