Enjoy an ad free experience by logging in. Not a member yet?
Register .
07-04-2007, 06:31 PM
PM User |
#1
Senior Coder
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
Checking if a value appears in an array
So I have this array which contains an array which contains values. I want to check if the value provided is inside the second array.
Here is my structure:
PHP Code:
$array =array(
"ARRAY2" =>array(
"Info" ,
"Board" ,
"License" ,
),
"ARRAY3" =>array(
"Structure" ,
"Edit" ,
"Add" ,
"Delete" ,
),
"ARRAY4" =>array(
"View" ,
"Search" ,
"Groups" ,
"Delete" ,
),
"ARRAY5" =>array(
"Main" ,
"Themes" ,
"Groups" ,
),
);
lets say I want to check if Groups is inside ARRAY 4. How would I do that? I know how to check if ARRAY 4 is inside array, but if you go down a level im not exactly sure how to do that.
07-04-2007, 07:02 PM
PM User |
#2
New Coder
Join Date: Jul 2007
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
With 2 minutes of thinking I would do this
PHP Code:
<?php $array =array( "ARRAY2" =>array( "Info" , "Board" , "License" , ), "ARRAY3" =>array( "Structure" , "Edit" , "Add" , "Delete" , ), "ARRAY4" =>array( "View" , "Search" , "Groups" , "Delete" , ), "ARRAY5" =>array( "Main" , "Themes" , "Groups" , ), ); foreach ( $array AS $key => $val_array ){ if( in_array ( 'Groups' , $val_array )){ // do something! echo "Found it in array['{$key}']!<br>" ; } } ?>
That's for checking all arrays but if you want know which key like ARRAY4 for example, you just have to use this syntax
PHP Code:
in_array ( "Groups" , $array [ 'ARRAY4' ]);
__________________
-
07-04-2007, 08:02 PM
PM User |
#3
Senior Coder
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
Heh, thanks, I forgot that you can call array inside an array by $array['ARRAY4']. That solved my problem.
07-04-2007, 08:09 PM
PM User |
#4
New Coder
Join Date: Jul 2007
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
Glad that helped
At first I wasn't sure if that would do it hehe
__________________
-
07-04-2007, 08:17 PM
PM User |
#5
Senior Coder
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
heh, yep.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 04:19 PM .
Advertisement
Log in to turn off these ads.