0

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?

LF00
  • 27,015
  • 29
  • 156
  • 295
  • Everything. It is impossible to return multiple things in php. First thing returns. Maybe the third thing is "returned" because it auto completes the tag. Also this: https://stackoverflow.com/questions/3451906/multiple-returns-from-function – dage5 May 28 '17 at 15:38
  • Possible duplicate of [Multiple returns from function](https://stackoverflow.com/questions/3451906/multiple-returns-from-function) – Matthias M May 28 '17 at 21:07

3 Answers3

2

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

Rizier123
  • 58,877
  • 16
  • 101
  • 156
LF00
  • 27,015
  • 29
  • 156
  • 295
0

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>";
    };  
Amit Gaud
  • 756
  • 6
  • 15
0

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>";
    };