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
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 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
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.