Jump to content

Searching a Mulitifunctional Array


sanfly

Recommended Posts

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

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.

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.