Home »
Imported messages »
comp.lang.php »
Help with searching arrays of objects
Help with searching arrays of objects [message #181129] |
Thu, 18 April 2013 00:47 |
daveh
Messages: 18 Registered: March 2013
Karma:
|
Junior Member |
|
|
Hello,
I know this has probably been asked before but I'm still a bit of a noob.
Given the following structure I need a way to get a "key" to the desired object using a members value.
Array
(
[0] => gnp Object
(
[m_server:gnp:private] => 127.0.0.1
[m_port:gnp:private] => 30000
[m_dat_file:gnp:private] => /tmp/data.file
[m_socket:gnp:private] => tcp_socket Object
(
[m_address] => 127.0.0.1
[m_portno] => 30000
[m_tcpSocket] => Resource id #13
)
[m_proc_num:gnp:private] => 132
[m_open_region:gnp:private] => region Object
(
[m_region_no] => 0
[m_nullsubs] => 0
[m_max_rec_len] => 256
[m_max_subsc_len] => 64
)
[m_cur_region_no:gnp:private] => 0
[m_name] => db_1
)
[1] => gnp Object <--------- This is the "object" I want and I need the "key" which in this case is 1
(
[m_server:gnp:private] => 127.0.0.1
[m_port:gnp:private] => 30000
[m_dat_file:gnp:private] => /tmp/data.file
[m_socket:gnp:private] => tcp_socket Object
(
[m_address] => 127.0.0.1
[m_portno] => 30000
[m_tcpSocket] => Resource id #14
)
[m_proc_num:gnp:private] => 133
[m_open_region:gnp:private] => region Object
(
[m_region_no] => 0
[m_nullsubs] => 0
[m_max_rec_len] => 256
[m_max_subsc_len] => 64
)
[m_cur_region_no:gnp:private] => 0
[m_name] => db_2 <----------------- Using the "key" m_name's value db_2 or db_1 if I want the other object
)
)
So I need a method to find the objects key using m_name's value. I'm thinking a foreach but not sure how to implement it in this case. The structure shown has been snipped quite a bit for brevity. There could be any number of these gnp
objects I need the key as a way to access them and perform class methods on them. Obviously the m_name value desired would be assigned to a variable first.
And there could be any number of objects stored in this array of objects.
Dave
|
|
|
Goto Forum:
Current Time: Sun Nov 24 13:34:43 GMT 2024
Total time taken to generate the page: 0.05401 seconds