Show sourcecode
The following files exists in this folder. Click to view.
webbserver/ovningar/functions/
functions1.php
functions2.php
functions3.php
functions4.php
functions5.php
functions6.php
functions_index.php
functions6.php
28 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>6</title>
</head>
<body>
<?php
// Funktion som ersätter jämna tal med 0, låter udda tal vara kvar
function ersätt(&$array) {
// Loopa genom alla element i arrayen
for ($i = 0; $i < count($array); $i++) {
// Kontrollera om talet är jämnt (delbart med 2)
if ($array[$i] % 2 == 0) {
$array[$i] = 0; // Ersätt jämna tal med 0
}
}
return $array;
}
$array = [1, 2, 3, 4, 5, 6];
echo implode(", ", $array), "<br>";
$array = ersätt($array);
echo implode(", ", $array);
?>
</body>
</html>