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
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
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.