note 31851 modified in function.key by danbrown

From: Date: Sat, 28 Mar 2009 23:11:52 +0000
Subject: note 31851 modified in function.key by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152568@lists.php.net to get a copy of this message
<?php $tab = array(); $tab[0] = 'php'; $tab[1] = '.'; $tab[2] = 'net'; // you will not enter the while // $key = 0, while will consider $key as false reset($tab); while ($key = key($tab) ) { echo $tab[$key]; next($tab); } // this will reset($tab); while (!is_null($key = key($tab) ) ) { echo $tab[$key]; next($tab); } // when key() can't return a 'key', it return NULL echo var_dump($key); ?> --was-- $tab = array(); $tab[0] = 'php'; $tab[1] = '.'; $tab[2] = 'net'; // you will not enter the while // $key = 0, while will consider $key as false reset($tab); while ($key = key($tab) ) { echo $tab[$key]; next($tab); } // this will reset($tab); while (!is_null($key = key($tab) ) ) { echo $tab[$key]; next($tab); } // when key() can't return a 'key', it return NULL echo var_dump($key); http://php.net/manual/en/function.key.php

« previous php.notes (#152568) next »