Hi anyOne.
I found into a script(I put an example) the loop
while in this way

$array = array('one', 'two', 'three', 'four');
$i = 0;
while($num = array_shift($array))
{
echo $num;
}

Is it a right way ?
I mean $num is a string not
a boolean and php.net say

If array is empty (or is not an array), NULL will be returned.

Put me right if I made a mistake.
Take care.

    By the way of shift
    get away $i = 0;
    I forgot it 🙂

      All this does is iterates through the array, starting with the first element [0], and adding 1 to it for each loop. When the last call to array_shift() returns false (because it cant shift any further) you will break out of the while loop.

      Im not 100% sure what your question actualy is, but there are other ways of doing this. Just as an example...

      $num = 0;
      while ($num <= count($array)) {
        echo $num;
        $num++
      }
      

        Hi.
        Tks so much for the reply.
        I asked for this question because of I'm not completely agree
        with this while use found in a php class:

        $blockToParseList = array();
        $blockToParseList[] = array('',$blockContent);
        while($blockToParse = array_shift($blockToParseList))
        {
        $blockToParse[1]
        The need is to parse the $blockContent
        }

        for array_shift in php.net

        If array is empty (or is not an array), NULL will be returned

        The use of 'while' should be limited to function which returned
        boolean value I'd like to know your opinion 🙂
        Take care.

          The last call will return null (not false), as your manual quote says. But PHP is a loosely-typed language to begin with, so, imo, it's cool to use implicit casts, and most PHP coders do. It would, again imo, be crippling not to.

            Hi.
            TKs so much man 😃
            I wanted to hear so.
            Take care.

              Write a Reply...