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! Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/ Share on other sites More sharing options...
Garethp Posted September 14, 2009 Share Posted September 14, 2009 echo $array['3373'][0]; Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/#findComment-917925 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]; } ?> Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/#findComment-917926 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? Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/#findComment-917928 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 Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/#findComment-917930 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 Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/#findComment-918245 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! Link to comment https://forums.phpfreaks.com/topic/174135-solved-need-help-with-an-array/#findComment-918256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.