How can I brake a foreach loop after two iterations, something like this:
foreach($posttags as $tags){
$tag1 = $tags->slug;
} --- this is the first iteration, stored in the variable $tag1
foreach($posttags as $tags){
$tag2 = $tags->slug;
} ---- this is the second iteration, stored in the variable $tag2
brake; --- brake the foreach loop
Any ideas?
The most obvious answer is not to use a foreach loop if you don’t want to loop through each item. Use some other looping structure, or grab the first and second items manually if that’s what you really want.