我有一个喜欢这个的多维数组:
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']的值与随机序列的索引值匹配 我想插入一个函数。
我无法弄清楚这一点。我认为我的问题在于callng ['hit']的每个值并与index进行比较。有谁知道如何做到这一点 ? 感谢
答案 0 :(得分:1)
将DaveRandom的评论放入答案中(稍作修改):
foreach ($outerArray as $index => $innerArray)
{
if($innerArray['hit'] === $index)
{
doSomething();
}
}
@DaveRandom - 如果我在此处发帖,请随时删除或重新发布此作为您自己的答案...
答案 1 :(得分:1)
foreach ($array as $key) {
if ($key['hit'] == $index)
{
// you function or logic here
}
}