Jump to content

Searching an array within an array within an array


Doublea

Recommended Posts

Hi guys,

 

I'm trying to search an array to show if a user is attending an event ID and output "You are attending this event".

 

I need to search the array 'data', then all the numbers, then check if the 'id' matches and if they 'attending' or 'not attending'.

 

I have figured out how to search the array using:

 

<?php
echo ((in_array('107510232628186', $movies['data'][]['id']))? 'You are attending the event' : 'You are not attending the event');
?> 

 

but it only outputs an error as I don't know how to search all the middle numbered arrays.

 

Here is my array:

 

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => Test2
                    [id] => 137233316308949
                    [rsvp_status] => attending
                )

            [1] => Array
                (
                    [name] => Party Animals
                    [id] => 107510232628186
                    [rsvp_status] => attending
                )

            [2] => Array
                (
                    [name] => Ibiza Opening Party @ EDEN [TICKETS]
                    [id] => 111456325542560
                    [rsvp_status] => attending
                )

        )

 

Think I'm probably missing a trick here, as it seems like it should be simple!

 

Hope someone can help :)

 

Cool thanks for the code - so it now shows attending three times, but I need to show only for one event id which is 'id'.

 

So I need to search for '107510232628186' in the array and then check if the 'rsvp_status' of this is attending and show this.

 

Any pointers?

Thanks jcbones.

 

Thing is, I'm still getting attending three times. I think I need to move down one level in the array. $movies['data'] as $user would be the numbered arrays [0],[1],[2] not inside of those numbered arrays.

 

Hence why it is showing attending three times.

 

How can I get down one level?

 

Thanks!

I'm sure you mean your getting attending once, and not attending twice.

 

If you are getting attending 3 times then there is 3 rows with the same id?

 

anyway i think what you want is to put an "if" statement inside the "foreach" loop. If the "$user['id']" is equal to the selected "id" then echo the result (Attending or not attending).

 

-cb-

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.