Retrieving a boolean value in a function using php -


   function sample($number){     if ($number % 2 == 0){     echo "even";     }else{     echo "odd";     }      sample(3); 

when replace echo return nothing happens? how know if returns something? below sample concerns me. in advance!

 function sample($number){     if ($number % 2 == 0){     return true;     }else{     return false;     }  sample(3); 

something definetly happens. aren't catching result.

// return true or false @ random function trueorfalse() {     return (rand(1, 10) > 5) ? true : false; }  // going check being returned print_r(trueorfalse()); // true print_r(trueorfalse()); // false print_r(trueorfalse()); // false print_r(trueorfalse()); // true 

you can use return value in if statements , such:

if (trueorfalse() == true) {     echo "it true time"; } 

the php manual tells us

values returned using optional return statement. type may returned, including arrays , objects. causes function end execution , pass control line called. see return more information.

additional reading


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -