Results 1 to 2 of 2

Thread: Warning: Undefined array key

  1. #1
    Junior Member
    Join Date
    Mar 2022
    Posts
    1

    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

  2. #2
    Administrator Steve R Jones's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    390
    You should post your question on our sister site here:

    https://board.phpbuilder.com/

Similar Threads

  1. C# array of strings
    By Xarzu in forum General Programming Questions
    Replies: 2
    Last Post: January 14th, 2009, 07:36 PM
  2. Raid Array Memory
    By Blunted One in forum Hardware
    Replies: 17
    Last Post: April 6th, 2007, 11:21 AM
  3. how do i rotate an array in C++?????
    By freejack in forum AntiOnline's General Chit Chat
    Replies: 2
    Last Post: March 14th, 2003, 09:37 AM
  4. While loop in PHP: undefined offset
    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
  •