For example, can I do:
if ($my_array = wp_get_category($id)) {
echo "asdf";
} else {
echo "1234";
}
If nothing is returned by the function, I want to go into the else statement.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, that will work, and the pattern is used quite often.
If
$my_arrayis assigned a truthy value, then the condition will be met.CodePad.
The inverse is also true…
A function that doesn’t return anything will return
NULL, which is falsey.CodePad.