2levelsabove Posted March 23, 2010 Share Posted March 23, 2010 OK so I know how tertiary operators work $videos = is_array($videodata) ? $videodata : 0; how ever can one do actions instead of just assigning values ? for example : (if true ) ? (do this ) ( else that) OR IN MY CASE (is_array($videodata)) ? return $videodata : return 0; Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/ Share on other sites More sharing options...
KevinM1 Posted March 23, 2010 Share Posted March 23, 2010 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030603 Share on other sites More sharing options...
2levelsabove Posted March 23, 2010 Author Share Posted March 23, 2010 It doesnt let me: (is_array($videodata)) ? return $videodata : return 0; However this works $videos = is_array($videodata) ? $videodata : 0; return $videos; Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030606 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 (is_array($videodata)) ? return $videodata : return 0; Are you using it within a function? Else it's not valid. Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030610 Share on other sites More sharing options...
2levelsabove Posted March 23, 2010 Author Share Posted March 23, 2010 Yes I am using it within a function. Why would that not work? Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030612 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 Yes I am using it within a function. Why would that not work? You cannot return a variable into the subscope, you must return the result of the IF statement first: return (is_array($videodata)) ? $videodata : 0; Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030616 Share on other sites More sharing options...
2levelsabove Posted March 23, 2010 Author Share Posted March 23, 2010 Thank you ! Now I get it. Quote Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030635 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.