Here's a simple php code:
if ( $var ) echo $value;
This statement checks if $var has value then echo it.
In fact, that's not what I want. I want to check the value of $var (which is a function such as 'is_single()' as in wordpress case).
--- update ---
To clairfy:
if ( $var ) echo 'var is true';
I don't want it to be a Boolean statement, I want it to check the value of $var, which in my case (Wordpress) $var = 'is_single()';
Where is_single()
is a function.
--- update 2 ---
Looks like what I want to achieve is to use a function instead of a string in the if statement.
Something like that:
if ( $var() ) instead of ( $var )
Though the $var
is stored as a string.
use:
isset($var)
Up to now, your code does not check if the variable ($var
) has a value. It evaluates a boolean expression. This means that your code fails for all values that evaluate to false, such as 0
or false
. Therefore, your variable can be set, can have a value and never get echoed. That's why you check whether the variable is set, using isset($var)
and then you can perform other checks or echo the contents.
See the php.net Manul for more Information => http://php.net/manual/en/function.isset.php
Thanks to N.B. for the further Explanation
Update:
The Wordpress Function Returns a boolean, therefore True
or False
if (is_single()) echo "is_single() is true";
That Displays is_single() is true if is_single()
Returns True
Update 2
<Input name="var" value="<?php echo is_single();?>"/>
Should do it.