RJP1 Posted February 16, 2011 Share Posted February 16, 2011 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 ) Link to comment https://forums.phpfreaks.com/topic/227862-how-do-you-check-an-array-in-an-array-in-an-array/ Share on other sites More sharing options...
silkfire Posted February 16, 2011 Share Posted February 16, 2011 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 } Link to comment https://forums.phpfreaks.com/topic/227862-how-do-you-check-an-array-in-an-array-in-an-array/#findComment-1174974 Share on other sites More sharing options...
RJP1 Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks a lot silkfire, That really helped! Good idea! Cheers, RJP1 Link to comment https://forums.phpfreaks.com/topic/227862-how-do-you-check-an-array-in-an-array-in-an-array/#findComment-1174977 Share on other sites More sharing options...
AbraCadaver Posted February 16, 2011 Share Posted February 16, 2011 Really no need to build a new array: foreach($array['data'] as $item) { if($item['id'] == '534890345_random_id') { echo $item['name']; break; } } Link to comment https://forums.phpfreaks.com/topic/227862-how-do-you-check-an-array-in-an-array-in-an-array/#findComment-1175082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.