May 7, 2013

Just little bit confusion with && , != and || in php

Deerox’s Questions:

I am just wondering how i can get success as echo without changing my if (.....) condition. do i need to add more condition or any function or an array? just a lil confused write now thanks. Just want to know if it will work this way or i have to write big codes for this condition 🙂

$petbuyer1 = 1;
$petbuyer2 = 2;
$petbuyer3 = 3;
$user_id = 1;
$petfom = "fomyes";
$fomon = "fomyes";

if (($petfom == $fomon) && ($user_id == $petbuyer1 || $user_id == $petbuyer2 || $user_id == $petbuyer3)) {
    echo "failed";
}else{
    echo "success";
}

Also tried :

if (($petfom == $fomon) && ($user_id != $petbuyer1 || $user_id != $petbuyer2 || $user_id != $petbuyer3)) {
    echo "failed";
}else{
    echo "success";
}

Seems like a typo error with $fomom. May be it should be $fomon.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!