Fabrizio Cocco
Fabrizio Cocco

Reputation: 171

Multiple return of one function

I'm using the function:

function findTeamFromID($teams,$ID) {
    $results = array_column($teams, 'langform', 'id_teams');
    return (isset($results[$ID])) ? $results[$ID] : FALSE;
};  

Now i want not only to replace the ID with the name, it should write a link to the detail page. I don't wanted to touch the return line so i made this:

function findTeamFromID($teams,$ID) {
    $results = array_column($teams, 'langform', 'id_teams');
    return "<a href=\"details.php?id=".$ID."\">";
    return (isset($results[$ID])) ? $results[$ID] : FALSE;
    return "</a>";
};  

Funny now is, that Return 1 and 3 appear and the href will be correctly created. But the second return doesn't appear anymore.

What did i make wrong?

Upvotes: 0

Views: 41

Answers (3)

LF-DevJourney
LF-DevJourney

Reputation: 28564

No you cannot have multi return value from php function. In your code, only the first return statement works.

Upvotes: 2

Amit Gaud
Amit Gaud

Reputation: 766

Use single quote in result EDIT:

  function findTeamFromID($teams,$ID) {
        $results = array_column($teams, 'langform', 'id_teams');
        return "<a href=\"details.php?id=".$ID."\">".
       (isset($results[$ID]) ? $results[$ID] : FALSE)
       . "</a>";
    };  

Upvotes: 0

Fabrizio Cocco
Fabrizio Cocco

Reputation: 171

Thanks for the hints. So i found the solution by myself.

    function findTeamFromID($teams,$ID) {
        $results = array_column($teams, 'langform', 'id_teams');
        return "<a href=\"details.php?id=".$ID."\">".
        (isset($results[$ID]) ? $results[$ID] : FALSE). "</a>";
    }; 

Upvotes: 0

Related Questions