Christian S.: Rückgabewert aus rekursiver Funktion

Beitrag lesen

Hi,

function getEntryId($entry_id=0)
{
$result=mysql_query("SELECT entry_id FROM...");
if(mysql_num_rows($result)>0)
  {
  $row=mysql_fetch_array($result);
  getEntryId($row['entry_id']);
  }
else
  {
  return $entry_id;
  }
}

$entry_id wird ja auch NIE mit einem Wert belegt...

Die Funktion getEntryId sollte immer einen return wert haben!

etwa so:

function getEntryId($entry_id=0)
{
   $result=mysql_query("SELECT entry_id FROM...");
   if(mysql_num_rows($result)>0)
   {
     $row=mysql_fetch_array($result);
     $entry_id = getEntryId($row['entry_id']);
   }
   return $entry_id;
}

Also wichtig ist natürlich, dass du das Ergebnis der rekursiven Aufrufe einer Variablen zuweist.

Gruß
Christian