dongyan1936 2010-02-23 09:22
浏览 75

匹配一维数组与二维数组

I'm having some problems grasping how to match a one-dimensional array with a two-dimensional array. So I have one array, a one-dimensional, that contains numbers (e.g. 1, 2, 3, 4, 5...) and one two-dimensional array that contains numbers and some text (e.g. [1][dog], [2][cat], [3][mouse]...)

So now what I want to do is to use the first array, to see if that matches the second arrays numbers, e.g. if array[0] (contains value '1') matches array2[x] then output the array2's text, array2[x][text].

Any help is appriciated!

EDIT:

As per request I've exported the arrays, I don't know if that'll help, but here we go:

arrayX ( 0 => '1', 
         1 => '2'
)
arrayY ( 0 => array ( 0 => 'cat' ), 
         1 => array ( 0 => 'dog' )
)

I suppose this'd work similar to a tag system? If arrayX contains an entry with the value '1', then compare this with arrayY and output the number-match.

  • 写回答

2条回答 默认 最新

  • dongtang1909 2010-02-23 09:28
    关注

    Do you mean that the second array is like the following: $array[0]['cat'] = 'dog'

    Or $array[0] = 'cat'

    If it's the latter, you can just iterate over the first array, outputting values from the second array like so

    foreach ($array1 as $key) {
     echo $array2[$key];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭