• PHP Pointers Problem (While)

    Maxim6m0cj Member

    i’ve problem with PHP. i want learning PHP and i read books, watching tutorials and i wrote this code by myself;

    
    

    why this code not working ? please help me.

  • Ganesh Member

    Use a foreach loop to iterate through an array…

    
        
  • ShikhaTan Member

    you should use foreach to loop over arrays, however, to answer your question as to why your code isn’t working:

    In PHP the integer 0 is falsy, the first element in your array is 0 so the while loop never executes (because the first condition is false), you would need to do a type-sensitive comparison to use while:

    while (($a = current($num)) !== false) { ... }
    

    Definitely use foreach though.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.