Jump to content

How do you check an array in an array in an array?


RJP1

Recommended Posts

Hi guys,

 

Could someone help me please? How do I check the following data foreach [id] and check to see if it the whole array has a certain ID in it? I can access individual data like this: $array['data'][0]['id']; but I'm not sure of the best way to check the array for a particular ID. Any ideas?

 

Thanks, RJP1

 

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => sdajskdhsajd
                    [category] => Application
                    [id] => 323635478887920
                    [created_time] => 878978978
                )

            [1] => Array
                (
                    [name] => askdjakdjasd
                    [category] => Application
                    [id] => 36741566509099181
                    [created_time] => 2011-02-11T15:41:14+0000
                )

            [2] => Array
                (
                    [name] => asdasdasdasds
                    [category] => Interest
                    [id] => 1150572090878508639
                    [created_time] => 2011-02-11T15:38:40+0000
                )

Do you want to check if any of the [id]s in [data] contain a certain ID? Like a "search within entire array"?

 

Try this to make an array of all [id]s:

 

$ids = array();
foreach $array['data'] as $item {
    $ids[] = $item['id'];
}

if (in_array('534890345_random_id', $ids)) {
    // do something here
}

 

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.