• 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

Multiple order by in WooCommerce

Laravel implode array items to new lines

sort() not affecting original array while inside foreach loop

php curl_exec() Connection refused when retrieving a remote image

loop through an anchor id

PHPExcel How to set conditional formatting to change cell background color based on cells values

Having issue with matching rows in the database using PDO

Log a user out of a website when they put their computer to sleep

Open a popup box after receiving result from ajax

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

Unable to guess the mime type as no guessers are available Laravel 5.2

How to make a foreign key not using primary key

virtctl works when executed via command line but not from php exec()

Sagepay Error The Vendor failed to provide a RedirectionURL

Parsing JSON File to array in PHP

About Contact Privacy policy Terms and conditions