1

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?

3
  • 1
    what do you want as the result? 'b'? Commented Sep 8, 2010 at 17:34
  • 3
    Your question doesn't make any sense, can you try and clarify what you need to do? Commented Sep 8, 2010 at 17:34
  • @everyone, he wants to show the value of key 2 and then remove it from the array (throw-out / bring-out). Commented Sep 8, 2010 at 18:01

2 Answers 2

6

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 )

Sign up to request clarification or add additional context in comments.

Comments

0

make new array you want to sperate specific elements that key

$newarr = array(2,5,8);
foreach($arr1 as v1){
foreach($arr2 as $k => $v2 ){
if (in_array($k,$newarr))
{
// process ... 
}
}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.