mrmut
asked on
"Multiple" PHP return function?
Hello, please note I am beginner at PHP.
I have a function that I would like to return, instead of echo it (echo breaks code at certain point). However, I don't have a clue hot to build and output that as I have a foreach there. Pls. see an example, you will understand it easily.
I have a function that I would like to return, instead of echo it (echo breaks code at certain point). However, I don't have a clue hot to build and output that as I have a foreach there. Pls. see an example, you will understand it easily.
function list_articles($condition, $number = 3, $indentation = 3)
{
if ($condition == "home")
{
$sql = "SELECT Date,Time,Article FROM Articles WHERE PUBLISHED = 1 ORDER BY Date DESC, Time DESC LIMIT " . $number;
}
//
else if ($condition == "archive")
{
$sql = "SELECT Date,Time,Article FROM Articles WHERE PUBLISHED = 1 ORDER BY Date DESC, Time DESC";
}
//
else if ($condition == "admin")
{
$sql = "SELECT Date,Time,Article FROM Articles ORDER BY Date DESC, Time DESC";
}
//
else
{
return FALSE;
}
//
//DB fetch, returns $result
//
$result = retrieve_from_database($sql); //Add another control here
//
// Print list
//
echo str_repeat("\t", $indentation) . "<ul>\n";
foreach($result as $value)
{
echo str_repeat("\t", $indentation) . "\t<li>" . datetime_converter($value["Date"]) . " - " . $value["Article"] . "</li>\n";
}
echo str_repeat("\t", $indentation) . "</ul>";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER