Jump to content

[SOLVED] need help with an array


work_it_work

Recommended Posts

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

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'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?

Well using the help provided here, i manage solve this problem :D

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.