Re: Hidden costs of PHP arrays?

From: Date: Wed, 28 Jan 2009 00:15:38 +0000
Subject: Re: Hidden costs of PHP arrays?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-287253@lists.php.net to get a copy of this message
2009/1/28 Clancy <clancy_1@cybec.com.au> > PHP arrays permit extremely concise programming; for example if I have all > my contacts in > an array $contacts, I can write: > > $my_phone_no = $contacts['clancy']['phone']; > > However it is clear that there must be a lot going on behind the scenes to > achieve this > simple result, as it requires some sort of search procedure. > > Is it possible to give any indication of the overheads and memory costs > that are involved > in such a statement, and of how well the search procedure is implemented? > > Also what the relative virtues of defining the same set of fields for every > contact, as > against either defining only the fields which actually hold values, as in > the following > examples? > > a: > $contacts['clancy']['home_address'] = 'jkjkjk'; > $contacts['clancy']['home_phone'] = 0123 4567; > $contacts['clancy'][' office_address''] = ''; > $contacts['clancy']['office_phone'] = ''; > $contacts['joe']['home_address'] = ''; > $contacts['joe']['home_phone'] = ''; > $contacts['joe']['office_address'] = 'jsfvkl'; > $contacts['joe']['office_phone'] = 'jsfvkl'; > > b; > $contacts['clancy']['home_phone'] = 0123 4567; > $contacts['clancy']['home_address'] = 'jkjkjk'; > $contacts['joe']['office_address'] = 'jsfvkl'; > $contacts['joe']['office_phone'] = 'jsfvkl'; > > And is there any advantage in always assigning the keys in the same order? > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Well, arrays of those types are, as far as I know, stored as hash tables. So you should look for how hash tables work. -eddy

« previous php.general (#287253) next »