Re: Multidimensional arrays (more and more...)

From: Date: Thu, 28 Nov 2002 18:17:02 +0000
Subject: Re: Multidimensional arrays (more and more...)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-126527@lists.php.net to get a copy of this message
Well, counting is easy... count($issue) will be correct. If you want to count things that match only specific elements, use things like: $c=0; foreach($issue as $what) if ( $year==2003 && $month>=5 ) $c++; As I said in the previous email, to sort by array elements, you'd need to use array_multisort. Something like... $sortkey=array(); foreach($issue as $what) $sortkey[]=$what['number']; array_multisort($issue,$sortkey); And for looping, foreach is still your best bet: foreach($issue as $key => $what) { if ($what['senttosubscribers']==0) $issue[$key]['description'].=" (EMPTY)"; else $issue[$key]['description'].=str_replace(" (EMPTY)","",$what['description']); } With regard to PHP being "screwey", I haven't found this -- I use multidimensional arrays quite a bit and find that they behave exactly as I would predict. Maybe I'm just lucky. ;-) p On Thu, Nov 28, 2002 at 09:55:25AM -0800, Mako Shark wrote: > > Wow. This goes way beyond simply printing > multidimensional arrays. Here's some sample data: > > $issue[]["number"] = "number"; > $issue[]["headline"] = "headling"; > $issue[]["writers"] = "writers"; > $issue[]["list"] = "list"; > $issue[]["senttosubscribers"] = "0"; > $issue[]["month"] = "05"; > $issue[]["year"] = "2003"; > $issue[]["description"] = "description"; > > What I need to do now is count(), sort() by number, > and loop through this array. > > I read that PHP is screwy when counting and sorting > multidimensional arrays, but they *have* to have come > up with a method, right? -- Paul Chvostek <paul@it.ca> Operations / Abuse / Whatever +1 416 598-0000 it.canada - hosting and development http://www.it.ca/

« previous php.general (#126527) next »