Doublea Posted August 1, 2010 Share Posted August 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/209534-searching-an-array-within-an-array-within-an-array/ Share on other sites More sharing options...
ChemicalBliss Posted August 1, 2010 Share Posted August 1, 2010 what is it for? the current user or all users? Use a loop: all: foreach($movies['data'] as $user){ echo($user['name']." is ".($user['rsvp_status'] == "attending")? "Attending" : "Not Attending"); } -cb- Quote Link to comment https://forums.phpfreaks.com/topic/209534-searching-an-array-within-an-array-within-an-array/#findComment-1093942 Share on other sites More sharing options...
Doublea Posted August 1, 2010 Author Share Posted August 1, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/209534-searching-an-array-within-an-array-within-an-array/#findComment-1093947 Share on other sites More sharing options...
jcbones Posted August 2, 2010 Share Posted August 2, 2010 $show_id = '107510232628186'; foreach($movies['data'] as $user){ echo($user['name']." is ".($user['rsvp_status'] == "attending" && $user['id'] == $show_id)? "Attending" : "Not Attending"); } Quote Link to comment https://forums.phpfreaks.com/topic/209534-searching-an-array-within-an-array-within-an-array/#findComment-1093985 Share on other sites More sharing options...
Doublea Posted August 2, 2010 Author Share Posted August 2, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/209534-searching-an-array-within-an-array-within-an-array/#findComment-1094151 Share on other sites More sharing options...
ChemicalBliss Posted August 2, 2010 Share Posted August 2, 2010 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- Quote Link to comment https://forums.phpfreaks.com/topic/209534-searching-an-array-within-an-array-within-an-array/#findComment-1094289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.