开发者

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 =>"a开发者_运维技巧a1",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?


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 )


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 ... 
}
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜