コード例 #1
0
ファイル: ex22.php プロジェクト: MetalMor/ExM7UF1
            break;
    }
    return $nou_array;
}
function mostra_dades($dades_actuals, $tipus_mostra)
{
    echo "<table border=\"1\" width=\"30%\">";
    echo "<tr><td colspan=\"" . count($dades_actuals) . "\"><b>";
    if ($tipus_mostra == 0) {
        echo "ORDENAT DE MAJOR A MENOR";
    } elseif ($tipus_mostra == 1) {
        echo "ORDENAT DE MENOR A MAJOR";
    } else {
        echo "DADES INICIALS SENSE ORDENAR";
    }
    echo "</b></td></tr><tr>";
    foreach ($dades_actuals as $dada => $valor) {
        echo "<td>{$valor}</td>";
    }
    echo "</tr></table>";
}
$dades = array(1 => 1, 2 => 5, 3 => 9, 4 => 3, 5 => -1, 6 => 4, 7 => 0, 8 => -7, 9 => 8, 10 => 6);
$ordre = array(2, 0, 1);
foreach ($ordre as $o) {
    mostra_dades(ordena_array($dades, $o), $o);
}
?>
        
    </body>
    
</html>
コード例 #2
0
ファイル: ex22.php プロジェクト: MetalMor/ExM7UF1
    }
}
function mostra_dades($dades_actuals, $tipus_mostra)
{
    if ($tipus_mostra == 0) {
        $missatge = "ARRAY ORDENAT DE MAJOR A MENOR";
    } elseif ($tipus_mostra == 1) {
        $missatge = "ARRAY ORDENAT DE MENOR A MAJOR";
    } else {
        $missatge = "ESTAT INICIAL DE L'ARRAY";
    }
    echo "<table border=\"1\">";
    echo "<tr align=center><td colspan=" . sizeof($dades_actuals) . "><b>" . $missatge . "</b></td><tr>";
    echo "<tr>";
    foreach ($dades_actuals as $dada) {
        echo "<td>" . $dada . "</td>";
    }
    echo "</tr>";
    echo "</table>";
}
$dades = array(1, 5, 9, 3, -1, 4, 0, -7, 8, 6);
mostra_dades($dades, -1);
ordena_array($dades, 0);
mostra_dades($dades, 0);
ordena_array($dades, 1);
mostra_dades($dades, 1);
?>
 
</body>
</html>