techker Posted February 3, 2012 Share Posted February 3, 2012 Hey guys i have <? echo $info['Status'] == 'Sold' ? "<span class='echo'>".$info['Status']."</span>" :"For sale"; ?> i need to add a second value to the == =='sold' or 'On hold' how can i do this? Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/ Share on other sites More sharing options...
Proletarian Posted February 3, 2012 Share Posted February 3, 2012 <? echo $info['Status'] == ('Sold' || 'on hold') ? "<span class='echo'>".$info['Status']."</span>" :"For sale"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1313919 Share on other sites More sharing options...
kicken Posted February 3, 2012 Share Posted February 3, 2012 <? echo ($info['Status'] == 'Sold' || $info['Status'] == 'on hold') ? "<span class='echo'>".$info['Status']."</span>" :"For sale"; ?> You have to repeat the variable, you can't just do two values separated by a ||. If you need more values, it may be more beneficial to use an array of values and the in_array function. Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1313949 Share on other sites More sharing options...
techker Posted February 3, 2012 Author Share Posted February 3, 2012 so basicly || is like an AND. thx for the help! Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1313995 Share on other sites More sharing options...
Drongo_III Posted February 3, 2012 Share Posted February 3, 2012 err no, || is like OR so basicly || is like an AND. thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1313999 Share on other sites More sharing options...
AyKay47 Posted February 3, 2012 Share Posted February 3, 2012 so basicly || is like an AND. thanks for the help! || is not like and, example, in your case if you had: <? echo ($info['Status'] == 'Sold' && $info['Status'] == 'on hold') ? "<span class='echo'>".$info['Status']."</span>" :"For sale"; ?> Using the && and operator, this would mean that Both conditions would have to be met in order for you to receive the TRUEnternary response. However in your case, since you are using the || or operator, only one of the conditions needs to be met in order for the TRUE ternary response to output. Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1314013 Share on other sites More sharing options...
Proletarian Posted February 4, 2012 Share Posted February 4, 2012 <? echo ($info['Status'] == 'Sold' || $info['Status'] == 'on hold') ? "<span class='echo'>".$info['Status']."</span>" :"For sale"; ?> You have to repeat the variable, you can't just do two values separated by a ||. If you need more values, it may be more beneficial to use an array of values and the in_array function. I didn't realize that. Thanks for the correction. Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1314304 Share on other sites More sharing options...
techker Posted February 4, 2012 Author Share Posted February 4, 2012 so basicly || is like an AND. thanks for the help! || is not like and, example, in your case if you had: <? echo ($info['Status'] == 'Sold' && $info['Status'] == 'on hold') ? "<span class='echo'>".$info['Status']."</span>" :"For sale"; ?> Using the && and operator, this would mean that Both conditions would have to be met in order for you to receive the TRUEnternary response. However in your case, since you are using the || or operator, only one of the conditions needs to be met in order for the TRUE ternary response to output. this is the one i need.since they want in red on hold or if the car is sold.but i understand the && and toke note of it.thx for the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/256297-2-values/#findComment-1314397 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.