RE: [PHP] Dispalying Arrays - Again

From: Date: Tue, 15 Apr 2003 10:09:28 +0000
Subject: RE: [PHP] Dispalying Arrays - Again
Groups: php.general 
Request: Send a blank email to php-general+get-143893@lists.php.net to get a copy of this message
> -----Original Message----- > From: Jack Dempsey [mailto:dempsejn@georgetown.edu] > Sent: 15 April 2003 02:48 > > you change the names a little bit in the "what i'm looking > for" section, but > i'm assuming that was just shorthand: > > <? > > $z['user'] = array('vernman', 'Marc', 'rich96', > 'lata7'); > $z['distance'] = array(0 => 0.0, 4 => 14.9, 9 => 15.0, 1 => 67.6); > > foreach($z['user'] as $k => $v){ > echo $v . ", " . array_shift($z['distance']) . > "<br>"; > } > ?> Yeeeuch!!! Why on earth use array_shift() here? (1) It's slow. (2) It destroys the array. (3) And, most importantly, it probably accesses the elements in the wrong order! foreach($z['user'] as $k => $v){ echo "$v, {$z['distance'][$k]}<br>"; } Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#143893) next »