PHP Complex If Else Statement
I am using Wordpress and it has code like this:
<?php
if (is_user_l开发者_开发技巧ogged_in()) {
?>
I want to add to it another set of if
statements that check for a variable. I don't know the correct syntax but in plain English I want to say, "if users are logged in and $string1 or $string2 is empty…"
Please assist.
if ( is_user_logged_in() && (empty($string1) || empty($string2)) ) {
if you need only one string to be empty but not both. use
if ( is_user_logged_in() && (empty($string1) ^ empty($string2)) ) {
if (user_is_logged_in() AND (strlen($str1) == 0 OR strlen($str2) == 0))
I will note that this will work if BOTH str1 and str2 have a zero length. If the variables may not be set, as opposed to having zero length use isset instead of strlen() == 0.
if (user_logged_in() && (empty($string1) || empty($string2))
This requires the user_logged_in() call to return true. At least one of $string1 or $string2 needs to be empty.
<?php if(is_user_logged_in() && (empty($string1) || empty($string2))) ?>
Good luck :)
精彩评论