Reputation: 39
Hi I am having trouble with the OR operators in this function and I am not sure why?
<?php if(isset($value['instagram_id']) && $value['instagram_id'] != NULL) || (isset($value['facebook_id']) && $value['facebook_id'] != NULL) || (isset($value['soundcloud_id']) && $value['soundcloud_id'] != NULL) || (isset($value['twitter_id']) && $value['twitter_id'] != NULL) || (isset($value['youtube_id'])) && $value['youtube_id'] != NULL) { ?>
Can someone please shed some light on what I am doing wrong?
Upvotes: 0
Views: 1261
Reputation: 51
if ($value['instagram_id'], $value['instagram_id'])) {
}
This will return true only if all arguments to isset()
are set and do not contain null.
Upvotes: 0
Reputation: 2975
well....if you want to evaluate all the statement in one condition, then you can reduce your if
statement to below
if(!empty($value['instagram_id']) || !empty($value['facebook_id']) || !empty($value['soundcloud_id']) || !empty($value['twitter_id']) || !empty($value['youtube_id']) ) {
}
from the Docs
empty() is essentially the concise equivalent to !isset($var) || $var == false
!empty
will also evaluate null
as false
Upvotes: 2
Reputation: 443
Try this:
<?php
if((isset($value['instagram_id']) && $value['instagram_id']) ||
(isset($value['facebook_id']) && $value['facebook_id']) ||
(isset($value['soundcloud_id']) && $value['soundcloud_id']) ||
(isset($value['twitter_id']) && $value['twitter_id']) ||
(isset($value['youtube_id']) && $value['youtube_id'])){
... //TODO something
}
?>
Upvotes: 0