Re: gettting last assigned key in an array

From: Date: Fri, 10 Feb 2006 21:16:30 +0000
Subject: Re: gettting last assigned key in an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-230228@lists.php.net to get a copy of this message
On Fri, February 10, 2006 1:39 pm, jonathan wrote: > i"m mapping some data from a sql select into a custom object that > will have a couple associative arrays. I have some code that I think > looks a little ugly such as: > > $x=0; > if($row['slot']>=2) > { > $this->menu_item[$x]['item_id']=$row['item_id']; > $this->menu_item[$x]['name']=$row['name']; > $this->menu_item[$x]['item_price']=$row['item_price']; > $x++; > } This seems more clear than the one below. > I'd rather do something like this: > if($row['slot']>=2) > { > $this->menu_item[]['item_id']=$row['item_id']; > $y=get_last_key(); > $this->menu_item[$y]['name']=$row['name']; > $this->menu_item[$y]['item_price']=$row['item_price']; > } http://php.net/end -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#230228) next »