note 46614 added to function.reset

From: Date: Sun, 17 Oct 2004 13:54:35 +0000
Subject: note 46614 added to function.reset
Groups: php.notes 
Request: Send a blank email to php-notes+get-78696@lists.php.net to get a copy of this message
Note that reset() will not affect sub-arrays of multidimensional array. For example, <?php $arr = array( 1 => array(2,3,4,5,6), 2 => array(6,7,8,9,10) ); while(list($i,) = each($arr)) { echo "IN \$arr[$i]<br>"; while(list($sub_i,$entry) = each($arr[$i])) { echo "\$arr[$i][$sub_i] = $entry<br>"; } } reset($arr); // Do the same again while(list($i,) = each($arr)) { echo "IN \$arr[$i]<br>"; while(list($sub_i,$entry) = each($arr[$i])) { echo "\$arr[$i][$sub_i] = $entry<br>"; } } ?> will print IN $arr[1] $arr[1][0] = 2 $arr[1][1] = 3 $arr[1][2] = 4 $arr[1][3] = 5 $arr[1][4] = 6 IN $arr[2] $arr[2][0] = 6 $arr[2][1] = 7 $arr[2][2] = 8 $arr[2][3] = 9 $arr[2][4] = 10 IN $arr[1] IN $arr[2] ---- Manual Page -- http://www.php.net/manual/en/function.reset.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46614 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46614&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46614&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46614&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46614&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46614&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46614&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46614&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78696) next »