drema2014 2012-05-24 12:47
浏览 33
已采纳

将多维数组中的数组值与索引进行比较

I have a multidimensional array that loks lik this:

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

  • 写回答

2条回答 默认 最新

  • dpoppu4300 2012-05-24 13:15
    关注

    To put DaveRandom's comment into an answer (with minor amends):

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

    @DaveRandom - feel free to delete or re-post this as your own answer if I'm posting out of turn here...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀