• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How to break out of a foreach once a condition is met?

phploopsforeachconditional


PHP Snippet 1:

if ($small_object->TIME == $sought_time) {
   break;       
}

PHP Snippet 2:

   $count = 0;
    ......
    ..
    ..
    ..
    ..
    ......    
    if (++$count == 5) break;

Related Snippets

Having issue with matching rows in the database using PDO

How to insert Google Adsense Code in PHP script?

PHP array_filter with arguments

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

Insert multidimensional array to codeigniter cart

How to set a domain name with php artisan serve

PHPSpreadsheet - How Do I Use Auto Migration Tool

Laravel/docker-compose/redis - Class 'Redis' not found

PHP: How to raise number to (tiny) fractional exponent?

Laravel 5 issue with wherePivot

Laravel SQL query midnight time not showing

PHPExcel file download using AJAX call

How to disable only_full_group_by option in Laravel

sort() not affecting original array while inside foreach loop

Adding one microsecond to Datetime object in PHP

About Contact Privacy policy Terms and conditions