How To Limit Foreach Loop in PHP?

You can limit the foreach loop to any repetition. I needed to limit the foreach loop to two repetition.
I have used array_slice method inside foreach loop as following:
foreach(array_slice($articles, 0, 2) as $row ):
It was so easy.
The array_slice() function returns selected parts of an array.
Syntax
array_slice(array,start,length,preserve)

Comments

Post a Comment

Popular Posts