sanfly Posted April 20, 2009 Share Posted April 20, 2009 Hi I have an array [EventsOptionsSignup] => Array ( [0] => Array ( [id] => 29 [event_option_id] => 14 [event_signup_id] => 11 [quantity] => 1 ) [1] => Array ( [id] => 30 [event_option_id] => 15 [event_signup_id] => 11 [quantity] => 2 ) ) I want to search the array where the [id] = $someValue Is there a simple way/php function to do this or do I just have to cycle through with a foreach loop? Cheers Link to comment https://forums.phpfreaks.com/topic/154919-searching-a-mulitifunctional-array/ Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 Pretty sure you're stuck with a foreach. If you need to search it often it may be worth generating a key array. Loop it once and set $keyArray[$key] = $value['id']. That way you can just search your keyarray (with in_array() - get the key with array_search()) and use that to get the correct data from your main data array. If you need me to explain more let me know. Link to comment https://forums.phpfreaks.com/topic/154919-searching-a-mulitifunctional-array/#findComment-814854 Share on other sites More sharing options...
laffin Posted April 20, 2009 Share Posted April 20, 2009 Yeah, I call em lookup arrays myself. its just an array, with just the info u search primarily on, with same keys <?php $EventsOptionsSignup = Array( Array( 'id' => 29, 'event_option_id' => 14, 'event_signup_id' => 11, 'quantity' => 1, ), Array( 'id' => 30, 'event_option_id' => 15, 'event_signup_id' => 11, 'quantity' => 2, ) ); // Create Lookup arrays foreach($EventsOptionsSignup as $key=>$val) $EventLookup[$key] = $val; ?> so now u can find the Event with in_array Link to comment https://forums.phpfreaks.com/topic/154919-searching-a-mulitifunctional-array/#findComment-814887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.