I know how to do this… I’ll give example code below. But I can’t shake the feeling that there’s a clever way to accomplish what I want to do without using a variable like $isfirstloop.
$isfirstloop = true;
foreach($arrayname as $value) {
if ($isfirstloop) {
dosomethingspecial();
$isfirstloop = false;
}
dosomething();
}
Is there any way to execute dosomethingspecial() only on the first loop, while executing dosomething() on every loop, without introducing a variable like $isfirstloop?
Thanks!
1 Answer