-
March 5th, 2022, 03:30 PM
#1
Junior Member
Warning: Undefined array key
hello everybody,
recently I started to teach myself php with the book Php & mysql by (Jochen Franke & Axel Borntrager).
Now I'm at lesson 6 Working with arrays: but after taking over the script I get the following Error:
Warning: Undefined array key 6 in C:\xampp\htdocs\Les - 6 Array 2.php on line 15.
It gives the values correctly. but always followed by the error Warning: Undefined array key. What strikes me is that this is always at the beginning of the while code.
I just don't understand where I'm making the mistake. can someone explain to me where i am making the mistake.
<html>
<head>
<title>array</title>
</head>
<body>
<?php
//Twee eenvoudige geindiceerde arrays maken
$sortiment=array("Tafel","Kast","Bed","Nachtkastje","Krukje","Stoel");
$aantal =array(1,5,884,34,6,12,77,93,21);
//Alle items in de array acher elkaar weergeven
echo "<b>Array ongesorteerd</b><br>";
echo "<b>Sortiment:</b>";
$i=0;
while($sortiment[$i]){
echo $sortiment[$i] . " ";
$i++;
}
echo "<br><b>Aantal:</b>";
$i=0;
while($aantal[$i]){
echo $aantal[$i] . " ";
$i++;
}
echo "<br><br>";
//Arrayelementen op de posities 2 en 4
echo "<b>Arrayelement 2 (Sortiment):</b> " . $sortiment[2] ."<br>";
echo "<b>Arrayelement 4 (Aantal):</b>" . $aantal[4] . "<br>";
echo "<br>";
//Aantal elementen in de Array berekenen
echo "<b>Aantal arrayelementen: </b><br>";
echo "<b>Sortiment: </b>" . count ($sortiment) . "<br>";
echo "<b>Aantal: </b>" . count ($aantal) . "<br>";
echo "<br>";
//Arrays oplopend orteren en weergeven
sort($sortiment);
sort($aantal);
echo "<b>Array oplopend gesorteerd</b><br>";
echo "<b>Sortiment: </b>";
$i=0;
while($sortiment[$i]){
echo $sortiment[$i] . " ";
$i++;
}
echo "<br><b>Aantal: </b>";
$i=0;
while($aantal[$i]){
echo $aantal[$i] . " ";
$i++;
}
echo "<br><br>";
//Arrays dalend sorteren
rsort($sortiment);
rsort($aantal);
echo "<b>Array dalend gesorteerd</b><br>";
echo "<b>Sortiment: </b>";
$i=0;
while($sortiment[$i]){
echo $sortiment[$i] . " ";
$i++;
}
echo "<br><b>Aantal: </b>";
$i=0;
while ($aantal[$i]){
echo $aantal[$i] . " ";
$i++;
}
echo "<br><br>";
//Maximum en Minimum van de Arrays berekenen
echo "<b>Maximum Sortiment: </b>" . max($sortiment) . "<br>";
echo "<b>Minimum Aantal: </b>" . min($sortiment) . "<br><br>";
echo "<b>Maximum Aantal: </b>" . max($aantal) . "<br>";
echo "<b>Minimum Aantal: </b>" . min($aantal);
?>
</body>
</html>
kind regards,
Kees
-
March 6th, 2022, 09:21 AM
#2
You should post your question on our sister site here:
https://board.phpbuilder.com/
Similar Threads
-
By Xarzu in forum General Programming Questions
Replies: 2
Last Post: January 14th, 2009, 07:36 PM
-
By Blunted One in forum Hardware
Replies: 17
Last Post: April 6th, 2007, 11:21 AM
-
By freejack in forum AntiOnline's General Chit Chat
Replies: 2
Last Post: March 14th, 2003, 09:37 AM
-
By Negative in forum Web Development
Replies: 1
Last Post: December 29th, 2002, 03:44 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|