English 中文(简体)
以索引比较多维阵列的数组值
原标题:comparing array value from multidimensional array with index

我有一个多维阵列, 翻来覆去的这个:

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  

    )

 )                     

I have a foreach loop which will loop through each letter of a random sequence and use the index to give each letter a number value. If the value of [ hit ] matches the index value of the random sequence i want to insert a function.

I cannot figure this out. I think my problem is in callng each value of [ hit ] and comparing with index. Does anyone know how to do this ? thanks

最佳回答

将DaveRandom的评论写成答案(稍作修正):

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

@DaveRandom - 随意删除或重贴这个作为您自己的答案,

问题回答
       foreach ($array as $key) {

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

        { 

      // you function or logic here

        } 

    }




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签