0
I need this function to be recursive, I’m beginner in php and I’m not quite sure how to do this. :/
<?php
function mostraArray() {
$cena=array($_REQUEST["numeroa"], $_REQUEST["numerob"], $_REQUEST["numeroc"], $_REQUEST["numerod"], $_REQUEST["numeroe"]);
for ($i=0; $i<=count($cena)-1; $i++) {
return $cena[$i];
if ($i<4){
return ", ";
}
}
}
function ordenaArray() {
$cena=array($_REQUEST["numeroa"], $_REQUEST["numerob"], $_REQUEST["numeroc"], $_REQUEST["numerod"], $_REQUEST["numeroe"]);
rsort($cena);
for ($i=0; $i<=count($cena)-1; $i++) {
return $cena[$i];
if ($i<4){
return ", ";
}
}
}
echo "<p align=\"center\">Números pela <u>ordem de saída</u>: ".mostraArray()."</p>";
echo "<p align=\"center\">Números pela <u>ordem decrescente</u>: ".ordenaArray()."</p>"
?>
Obs: It’s for php class, that’s the exercise
Do the two functions need to be recursive? has some reason?
– rray
@rray It’s for php class, that’s the exercise: http://imgur.com/BWxgj6Z
– Filipe Silva
Using only that can solve:
$arr = array(5, 1, 25, 12, 3);
andarsort($arr);
.– Daniel Omine
But it needs to be with recursive function.. :/
– Filipe Silva