work_it_work Posted September 14, 2009 Share Posted September 14, 2009 I have an array like this: $array = array ("3279" => array ("AMC", 0), "3373" => array ("CL", 0), "3374" => array ("Integra", 0), "3375" => array ("Legend", 0), "3367" => array ("MDX", 0), ); ?> What i want is to search in the array for the number and pull out the name EG: search number 3373 and pull out CL (nothing else) Help me please!!! Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 14, 2009 Share Posted September 14, 2009 echo $array['3373'][0]; Quote Link to comment Share on other sites More sharing options...
AviNahum Posted September 14, 2009 Share Posted September 14, 2009 i'm not sure, but try this: <?php $array = array ("3279" => array ("AMC", 0), "3373" => array ("CL", 0), "3374" => array ("Integra", 0), "3375" => array ("Legend", 0), "3367" => array ("MDX", 0), ); if ( in_array("3373" , $array) ) { echo $array['3373'][0]; } ?> Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 14, 2009 Share Posted September 14, 2009 i'm not sure, but try this: <?php $array = array ("3279" => array ("AMC", 0), "3373" => array ("CL", 0), "3374" => array ("Integra", 0), "3375" => array ("Legend", 0), "3367" => array ("MDX", 0), ); ?> if ( in_array("3373" , $array) ) { echo $array['3373'][0]; } ?> I don't think you can do that, can you? Because 3373 is the key, doesn't in_array just check the value? Wouldn't use you if(isset($array['3373'])) instead? Quote Link to comment Share on other sites More sharing options...
AviNahum Posted September 14, 2009 Share Posted September 14, 2009 yea, you right... my bad... sorry... but i can use array_key_exists instead in_array Quote Link to comment Share on other sites More sharing options...
work_it_work Posted September 14, 2009 Author Share Posted September 14, 2009 Thanks for your replies but this time it doesn't work The page remains blank, no output row is shown Quote Link to comment Share on other sites More sharing options...
work_it_work Posted September 14, 2009 Author Share Posted September 14, 2009 Well using the help provided here, i manage solve this problem Here it is the complete script: <?php $trigger = 3373; $array = array ("3279" => array ("AMC", 0), "3373" => array ("CL", 0), "3374" => array ("Integra", 0), "3375" => array ("Legend", 0), "3367" => array ("MDX", 0), ); ?> if ( array_key_exists($trigger , $array) ) { echo $array[$trigger][0]; } ?> Thanks again for your help guys! Quote Link to comment 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.