is115-php/modul4/index4_1.php

40 lines
1001 B
PHP

<?php include '../common.php'; ?><!DOCTYPE html>
<html lang="no">
<head>
<title><?=title();?></title>
<link rel="stylesheet" href="../index.css">
</head>
<body>
<div class="container">
<h1><?=title();?></h1>
<h4><?=getNavigation();?></h4>
<h2>Innhold i matrise</h2>
<?php
// Alternativt: $matrise = array(0, 3 => 3, 5 => 5, 7 => 7, 8 => 8, 15 => 15);
// Personlig syns jeg følgende er mer oversiktlig ved slike lengder:
$matrise[0] = 0;
$matrise[3] = 3;
$matrise[5] = 5;
$matrise[7] = 7;
$matrise[8] = 8;
$matrise[15] = 15;
echo "<p>Innholde i matrisen ved bruk av <code>print_r()</code>:<pre>";
print_r($matrise);
echo "</pre></p>";
echo "<p>Innholdet skrevet ut gjennom en <code>foreach()</code>-løkke:<br>\n";
// Foreach løkke som skriver ut hele $matrise'ns innhold.
foreach($matrise as $key => $val){
echo '$matrise['.$key.'] = '.$val.";<br>\n";
}
echo "</p>";
?>
</div>
</body>
</html>