return false inside a condition in loop not working jquery code example

Example 1: return false inside loop of function php

$items = ['a' , 'b' , 'c']; 

foreach($items as $item) 
{ 
   if($item == 'a') 
   {
       return true; // the foreach will stop once 'a' is found and returns true. 
   }

   return false; // if 'a' is not found, the foreach will return false.
}

Example 2: return false inside loop of function php

for($i = 0; $i < 5; $i ++) {
    if($var[$i] === '')
     { set_some_condition; 
       break;
     }
}

if (some_condition)
 return;

Tags:

Php Example