Thoughts that's escape, only details.

PHP – Limit Array Results

$count = 0;
foreach ($records as $record) {
print $record;
if ($count == 5) break;

Category: Scripting

Tagged: , , ,

2 Responses

  1. gfdsa says:

    This snipplet assumes you have all your records in an array
    If there id a way to get records one by one you’d better off with that for not hitting memory limits of php
    Which means fetching rows instead of fetching all result from db or reading files line by line

  2. Thanks..exactly what I was looking for to limit the number of fetched result from db..used it to limit features items in opencart.

Leave a Reply

You must be logged in to post a comment.