Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.