code=
Code: Selecteer alles
<html>
<head>
<title>Arrays in PHP</title>
</head>
<body>
<?php
// Twee eenvoudige geïndexeerde arrays maken
$assortiment=array("tafel","kast","bed","nachtkastje","kruk","stoel");
$getallen=array(1,5,884,34,6,12,77,93,21);
// Alle arraywaarden na elkaar weergeven
echo "<b>Arrays ongesorteerd</b><br>";
echo "<b>Assortiment: </b>";
$i=0;
while($assortiment[$i])
{
echo $assortiment[$i] . " ";
$i++;
}
echo "<br><b>Getallen: </b>";
$i=0;
while($getallen[$i])
{
echo $getallen[$i] . " ";
$i++;
}
echo "<br><br>";
// Arraywaarden op de posities 2 en 4 teruggeven
echo "<b>Arraywaarde 2 (assortiment):</b> " . $assortiment[2] . "<br>";
echo "<b>Arraywaarde 4 (getallen): </b>" . $getallen[4] . "<br>";
echo "<br>";
// Aantal waarden in de array vaststellen en teruggeven
echo "<b>Aantal arraywaarden: </b><br>";
echo "<b>Assortiment: </b>" . count($assortiment) . "<br>";
echo "<b>Getallen: </b>" . count($getallen) . "<br>";
echo "<br>";
// Arrays oplopend sorteren en dan weergeven
sort($assortiment);
sort($getallen);
echo "<b>Arrays oplopend gesorteerd</b><br>";
echo "<b>Assortiment: </b>";
$i=0;
while($assortiment[$i])
{
echo $assortiment[$i] . " ";
$i++;
}
echo "<br><b>Getallen: </b>";
$i=0;
while($getallen[$i])
{
echo $getallen[$i] . " ";
$i++;
}
echo "<br><br>";
// Arrays aflopend sorteren en dan weergeven
rsort($assortiment);
rsort($getallen);
echo "<b>Arrays aflopend gesorteerd</b><br>";
echo "<b>Assortiment: </b>";
$i=0;
while($assortiment[$i])
{
echo $assortiment[$i] . " ";
$i++;
}
echo "<br><b>Getallen: </b>";
$i=0;
while($getallen[$i])
{
echo $getallen[$i] . " ";
$i++;
}
echo "<br><br>";
// Maximum en minimum van de arrays bepalen
echo "<b>Maximum assortiment: </b>" . max($assortiment) . "<br>";
echo "<b>Minimum assortiment: </b>" . min($assortiment) . "<br><br>";
echo "<b>Maximum getallen: </b>" . max($getallen) . "<br>";
echo "<b>Minimum getallen: </b>" . min($getallen);
?>
</body>
</html>
Code: Selecteer alles
Arrays ongesorteerd
Assortiment: tafel kast bed nachtkastje kruk stoel
Notice: Undefined offset: 6 in c:\program files\easyphp1-7\www\2\arrays_functies.php on line 15
Getallen: 1 5 884 34 6 12 77 93 21
Notice: Undefined offset: 9 in c:\program files\easyphp1-7\www\2\arrays_functies.php on line 21
Arraywaarde 2 (assortiment): bed
Arraywaarde 4 (getallen): 6
Aantal arraywaarden:
Assortiment: 6
Getallen: 9
Arrays oplopend gesorteerd
Assortiment: bed kast kruk nachtkastje stoel tafel
Notice: Undefined offset: 6 in c:\program files\easyphp1-7\www\2\arrays_functies.php on line 44
Getallen: 1 5 6 12 21 34 77 93 884
Notice: Undefined offset: 9 in c:\program files\easyphp1-7\www\2\arrays_functies.php on line 50
Arrays aflopend gesorteerd
Assortiment: tafel stoel nachtkastje kruk kast bed
Notice: Undefined offset: 6 in c:\program files\easyphp1-7\www\2\arrays_functies.php on line 62
Getallen: 884 93 77 34 21 12 6 5 1
Notice: Undefined offset: 9 in c:\program files\easyphp1-7\www\2\arrays_functies.php on line 68
Maximum assortiment: tafel
Minimum assortiment: bed
Maximum getallen: 884
Minimum getallen: 1
Het zal wel simpel zijn, maar ik als nieuweling kom er niet uit.
Herman
Veranderingen:
- Verplaatst
- Blauwe tekst weg
- Code tags gebruikt
-- Bee