#19943 [Com]: Ragged array returns undefined results

From: Date: Thu, 17 Oct 2002 00:54:16 +0000
Subject: #19943 [Com]: Ragged array returns undefined results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-22619@lists.php.net to get a copy of this message
ID: 19943 Comment by: su-php@bossi.com Reported By: su-php@bossi.com Status: Open Bug Type: Arrays related Operating System: Win2K PHP Version: 4.2.1 New Comment: However, the following codes does work, even though the array is still ragged: <? $ragged = array(); for ( $count = 0; $count < 10; $count++ ) { $ragged['idx'][$count] = 'ragged '.$count; $ragged[$count] = 'single '.$count; } ?> <html><head></head><body> <table border="1"> <tr> <td>Expected</td><td>Actual</td> <td>Expected IDX</td><td>Actual IDX</td> </tr> <? for ( $count = 0; $count < 10; $count++ ) { ?> <tr> <td> <?= 'single '.$count ?> </td><td> <?= $ragged[$count] ?> </td> <td> <?= 'ragged '.$count ?> </td><td> <?= $ragged['idx'][$count] ?> </td> </tr> <? } ?> </table></body></html> Previous Comments: ------------------------------------------------------------------------ [2002-10-16 19:50:57] su-php@bossi.com When using an array that has ragged indices, the value in the array is undefined. Well, actually it can be defined, but it is unexpected. No errors or warnings are reported. Sample Code: <? $ragged = array(); for ( $count = 0; $count < 10; $count++ ) { $ragged[$count] = 'single '.$count; $ragged[$count]['idx'] = 'ragged '.$count; } ?> <html><head></head><body> <table border="1"> <tr> <td>Expected</td><td>Actual</td> <td>Expected IDX</td><td>Actual IDX</td> </tr> <? for ( $count = 0; $count < 10; $count++ ) { ?> <tr> <td> <?= 'single '.$count ?> </td><td> <?= $ragged[$count] ?> </td> <td> <?= 'ragged '.$count ?> </td><td> <?= $ragged[$count]['idx'] ?> </td> </tr> <? } ?> </table></body></html> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19943&edit=1

« previous php.bugs (#22619) next »