Skip to content
Advertisement

How can I get specific value in array

I will explain clearly

$array  = array("1" => array(0 =>"aa",1 =>"bb", 2 => "cc",3=>"dd"),
                "2" => array(0 =>"aa1",1 =>"bb1", 2 => "cc1",3=>"dd1"));

In this two dimension are

$array2[$a][$b];

I know $a value and $b is unknown

If I using $a =1, I want to filter array(0 =>"aa",1 =>"bb", 2 => "cc",3=>"dd") this array

But I need to get the second array element. Any function is available to do that?

Advertisement

Answer

This is how you do it:

$a = array(1=>'a', 2=>'b', 3=>'c');

//display the value with key 2:
echo $a[2];

//remove the value with key 2 (throw-out / bring-out in your language)
unset($a[2]);

//now display whole array to show that value with key 2 is gone
print_r($a);

This outputs:

b

And then it outputs:

Array ( [1] => a [3] => c )

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement