Objects as array key names??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux