Objects as array key names??

From: Date: Sat, 15 Mar 2008 22:02:36 +0000
Subject: Objects as array key names??
Groups: php.general 
Request: Send a blank email to php-general+get-271648@lists.php.net to get a copy of this message
This question should probably be directed at the PHP Internals list, but I thought I would start by asking here first if anybody would even use this feature. It has been brought to my attention that with Perl and Ruby, you can use Objects as the value of the key within an array. The examples that were shown to me make me think that this would be an awesome ability to have within PHP. Here is an example of how I would use such a feature. I have a table of "customers". I have a table customers "contact_locations". This table has a reference ID back to the "customers" table. Now, in my array of information that I build I have this. $res = query('Select c_id, c_first_name, c_last_name FROM customers'); $customers = array(); while ( $row = fetch_assoc($res) ) { $customers[$row]['contact_locations'] = array(); $SQL = "SELECT * FROM contact_locations WHERE c_id={$row['c_id']}"; $loc_res = query($SQL); while ( $loc_row = fetch_assoc($loc_res) ) { $customers[$row]['contact_locations'][] = $loc_row; } } Now, contained within one array "$customers" I have all the information that would be needed for displaying any type of information related to a customer or a customers location. By doing having this feature, I could build the ability to do xPath searches within the base array. That would be nice. Anyways, what do you all think? Worth it or not? Jim Lucas

« previous php.general (#271648) next »