What are some alternative methods to counting records in PHP besides using the count() function?

Using the count() function in PHP to count records can sometimes be inefficient, especially when dealing with large datasets. An alternative method is to loop through the records and increment a counter variable for each record found. This method can be more efficient for large datasets as it does not require storing the entire dataset in memory.

// Alternative method to count records in PHP without using count() function
$counter = 0;
foreach ($records as $record) {
    $counter++;
}

echo "Total records: " . $counter;