jd2007 Posted August 8, 2007 Share Posted August 8, 2007 <?php class StringManipulation { function selectOut($string, $occur) { $start=0; return $string."<br />".$occur."<br />"; $num=strrchr($string, $occur); return $num; //return substr($string, $start, strlen($string)-$num); } } $string2=new StringManipulation; $str="Hello World"; echo $string2->selectOut($str, "o"); ?> this : return $string."<br />".$occur."<br />"; returns the result i want...but this: return $num; returns nothing... why ? Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/ Share on other sites More sharing options...
Guardian-Mage Posted August 8, 2007 Share Posted August 8, 2007 I may be mistaken, but I believe you can only use return once. It doesn't look to hard to return everything you want with one return, so you should try that. After it sends the first return, I think the function stops Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/#findComment-318431 Share on other sites More sharing options...
emehrkay Posted August 8, 2007 Share Posted August 8, 2007 once a successful return is executed, everthing else under it (in a function/method) is ignored. my advice would be to return the var that meets the scope of the function, and set a class property for the other variable: $this->_var = $var; Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/#findComment-318667 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 I may be mistaken, but I believe you can only use return once. It doesn't look to hard to return everything you want with one return, so you should try that. After it sends the first return, I think the function stops yahhh Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/#findComment-318969 Share on other sites More sharing options...
Stopofeger Posted August 16, 2007 Share Posted August 16, 2007 Once you return, that is the end of the function. You can return only one value. Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/#findComment-325514 Share on other sites More sharing options...
Barand Posted August 23, 2007 Share Posted August 23, 2007 Once you return, that is the end of the function. You can return only one value. ... but that one value that you return can be an array of many values Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/#findComment-332417 Share on other sites More sharing options...
keeB Posted August 24, 2007 Share Posted August 24, 2007 Once you return, that is the end of the function. You can return only one value. ... but that one value that you return can be an array of many values Absolutely true! You should break these out in to 2 functions. Quote Link to comment https://forums.phpfreaks.com/topic/63859-in-the-class-below-in-function-selectout-why-cant-i-return-twice/#findComment-332583 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.