RE: [PHP] Numerical refs to assoc array suddenly "undefined offset"??

From: Date: Mon, 02 Jul 2001 16:14:07 +0000
Subject: RE: [PHP] Numerical refs to assoc array suddenly "undefined offset"??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55859@lists.php.net to get a copy of this message
mysql returns an assoc array that also have numerical keys, perhaps you're thinking of that... to my knowledge, PHP never supported numeric & string indexing to it's assoc. arrays... i've tested the code below on PHP v4.0.4 and v4.0.6 and it runs the same: numerical index values return nothing. <? $bar = array ( 'foo' => 'first', 'bar' => 'second', 'more' => 'third', ); $my_arr['foo']='first'; $my_arr['bar']='second'; $my_arr['more']='third'; echo "<p>" . $my_arr[0] . "</p>\n"; echo "<p>" . $my_arr[1] . "</p>\n"; echo "<p>" . $my_arr[2] . "</p>\n"; echo "\n"; echo "<p>" . $bar[0] . "</p>\n"; echo "<p>" . $bar[1] . "</p>\n"; echo "<p>" . $bar[2] . "</p>\n"; for($i=0;$i<count($my_arr);$i++) { echo "<p>" . $my_arr[$i] . "</p>\n"; } for($i=0;$i<count($bar);$i++) { echo "<p>" . $my_arr[$i] . "</p>\n"; } while ( list($k,$v) = each($bar) ) { print "$k = $v\n"; } ?>

« previous php.general (#55859) next »