Jump to content

In the class below, in function selectOut , why can't i return twice ?


jd2007

Recommended Posts

<?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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.