I want to echo ‘success’ if the variable is true. (I originally wrote “returns true” which only applies to functions.
$add_visits = add_post_meta($id, 'piwik_visits', $nb_visits, true);
if($add_visits == true){
echo 'success';
}
Is this the equivalent of
$add_visits = add_post_meta($id, 'piwik_visits', $nb_visits, true);
if($add_visits){
echo 'success';
}
Or does $add_visits exist whether it is ‘true’ or ‘false’;
Testing
$var == trueis the same than just testing$var.You can read this SO question on comparison operator.
You can also read PHP manual on this topic.
Note: a variable does not return
true. It istrue, or it evaluates totrue. However, a function returnstrue.