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; 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. 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; 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. 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? 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; 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. Link to comment https://forums.phpfreaks.com/topic/196251-actions-tertiary-operators/#findComment-1030635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.