0

I have simple codes down below :

   $i = 0;    
    $array = array('name','email','address');

    while ($array[$i]) {
    echo "$array[$i]<br>";

    $i++;
    }

My problem : After echoing name, email, address without problem, It generates an error message "Undefined offset: 3". What is I insist to use WHILE loop instead of IF condition. How to deal with the error. Thank you

  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – user3942918 Mar 03 '17 at 06:15
  • 2
    use :`while (isset($array[$i])) {` to solve your problem. you should search and try before asking. – Suchit kumar Mar 03 '17 at 06:18
  • Thank you Suchit kumar my bro , you solved my problem – Lion Gordon Mar 03 '17 at 06:20

1 Answers1

0
<?php
$array = array('name','email','address');
for ($i=0; $i<sizeof($array);$i++) {
    echo "$array[$i]<br>";
}
?>
Rushil K. Pachchigar
  • 1,175
  • 2
  • 18
  • 38