php - how works or operator in if statements and print


I have two questions

1) how can i make php to check getnext() function,if it exists or what value it has ???

$a = 1;
if($a == 1 or getnext()== 1){
    echo "yeap";                 //this works

2)i want to write condition -- if $a or $b is equal to 1 , print the variable name that has the value of 1.

Is it possible to do in php ??can i do it this way???

if($a ==1 or $b==1){
    print($a or $b);    

thanks in advance:)




You could for example do as follows :

if($a ==1 || $b==1){
   print (($a == 1)? $a : $b);



For your first question,

yourgetnext() function must be return some valid integer value then only you can compare it with integer 1.

for second, You should write

if($a == 1 && $b == 1){
    echo 'both are 1';
else if($a == 1){
    echo '$a is 1';
else if($b == 1){
    echo '$b is 1';
    // both are not 1

also see this links, logical operators or vs || (double pipe) in php

PHP: return value from function and echo it directly?




You write condition? You use if and else, if no else in if you put return. Goodluck

People are also looking for solutions to the problem: php - Push related object data from one array into another array while relating on a shared column value


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.