0

我有一个像这样的多维数组:

Array
(
[0] => Array
    (
        [name] => >chr1:2198584545754_genome_1000+
        [score] => 511
        [hit] => 50   

    )

[1] => Array
    (
        [name] => >chr2:2198581212154_genome_1000+
        [score] => 620
        [hit] => 80   

    )

[2] => Array
    (
        [name] => >chr3:2115151215754_genome_1000+
        [score] => 666
        [hit] => 90   

    )

[3] => Array
    (
        [name] => >chr4:2198584545754_genome_1000+
        [score] => 750
        [hit] => 50 

    )

[4] => Array
    (
        [name] => >chr5:1218455145754_genome_1000+
        [score] => 800
        [hit] => 100  

    )

[5] => Array
    (
        [name] => >chr6:1231354645454_genome_1000+
        [score] => 850
        [hit] => 110  

    )

[6] => Array
    (
        [name] => >chr7:1231213211134_genome_1000+
        [score] => 900
        [hit] => 120  

    )

 )                     

我有一个 foreach 循环,它将遍历随机序列的每个字母,并使用索引给每个字母一个数字值。如果 ['hit'] 的值与随机序列的索引值匹配,我想插入一个函数。

我无法弄清楚这一点。我认为我的问题在于调用 ['hit'] 的每个值并与索引进行比较。有谁知道如何做到这一点 ?谢谢

4

2 回答 2

1

将 DaveRandom 的评论放入答案中(稍作修改):

foreach ($outerArray as $index => $innerArray)
{
    if($innerArray['hit'] === $index)
    {
        doSomething();
    }
}

@DaveRandom - 如果我在这里不按顺序发布,请随意删除或重新发布此作为您自己的答案...

于 2012-05-24T13:15:40.613 回答
1
       foreach ($array as $key) {

       if ($key['hit'] == $index)

        { 

      // you function or logic here

        } 

    }
于 2012-05-24T13:29:56.683 回答