0

I have been doing some simple php codes with tables and arrays

<table>
    <thead>
    <tr>
        <th># </th>
        <th>Name</th>
        <th>Governor</th>
        <th>Party</th>
        <th>Website</th>
    </tr>
    </thead>
    <tbody>
    <?php
    $j = 1;
    $x = 0;
    while ($x < $arrayLength){
        $x++;
        $getData = explode("-",$separatedData[$x]);
        $dataLength = count($getData);?>
    <tr>
        <td>
            <?php echo $j++ ?>
        </td>
        <td>
            <?php
            $properString = str_replace($unwantedCharacters, "", $getData[0]);
            echo $properString;
            ?>
        </td>
        <td>
            <?php echo $getData[1] ?>
        </td>
    </tr>
    <?php } ?>
    </tbody>
</table>
</body>

and I am getting this error "Undefined offset: 47"

Please I am not really use to php and I do not understand why I am getting this.

Jimmyjbk
  • 351
  • 3
  • 20
  • which of these lines is lines 47? I presume this one'while ($x < $arrayLength)' – Jacopo Mosconi May 28 '20 at 18:10
  • 1
    You're iterating $x at the beginning of the loop. PHP starts array indexes at 0, so you need to iterate it at the end, and check for <= at the start. If you've defined the indexes yourself, then you need to make sure the array index exists before you try to use it. – aynber May 28 '20 at 18:10
  • Where does $arrayLength come from? Is it the same length as $separatedData? If so, maybe it is easier to iterate over $separatedData using a foreach loop. – Bas Matthee May 28 '20 at 19:52

0 Answers0