Jump to content

PHP of one php condition is true


AniqueAli

Recommended Posts

<?php
$id1 = '5' ;
$id = array(1,2,3,4,5,6,7);

    foreach($id as $value){
if($id1==$value){
    echo 'One of them matches, ' ;
    echo 'Do not execute command <BR>' ;
} ////// if ends here
} ////// loop ends here

?>

 

How to do something if all statements are false ?

like when id $id1 = '10' , ?

Link to comment
https://forums.phpfreaks.com/topic/292075-php-of-one-php-condition-is-true/
Share on other sites

However, if you do need to loop and process all the values in the array then you can check this way

<?php
$id1 = '5' ;
$id = array(1,2,3,4,5,6,7);
$found = 0;                     // set a flag variable to FALSE
foreach($id as $value){
    if($id1==$value){
        echo 'One of them matches, ' ;
        echo 'Do not execute command <BR>' ;
        $found = 1;             // set the flag to TRUE if found
    }
}

if (!$found) {                  // use flag to see if it was found
    // do 'not found' action
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.