嗨数组里面,我想知道是否有一个好的算法来搜索一个数组,它是另一个数组内内子的,搜索子串在PHP
我有类似:
阵列(
[0] => Array(
[0] => img src="1" />
[1] => img src="2" alt="" class="logo i-dd-logo" />
[2] => img src="3" alt="" />
[3] => img src="4" width="21" height="21" alt="" class="i-twitter-xs" />
[4] => img src="myTarget" width="21" height="21" alt="" class="i-rss" />
[5] => <img class="offerimage" id="product-image" src="6" title="" alt=""/>
[6] => <img class="offerimage" id="product-image" src="7" title="" alt=""/>
[7] => <img class="offerimage" id="product-image" src="8" title="" alt=""/>
[8] => <img src="9" width="16" height="16" />
)
[1] => Array(
[0] => src="1"
[1] => src="a" alt="" class="logo i-dd-logo"
[2] => src="b" alt=""
)
)
我想要做的是要知道目标的位置,例如[0] [4],但它并不总是相同
我现在正在做的是在另外一段时间内检查whith strpos的子字符串,但也许有更好的方法来做到这一点,有什么建议吗?
感谢一切
更新代码:
$ I = -1;
的foreach($ IMG为$ outterKey => $ outter){
foreach($outter as $innerKey=>$inner){ $pos = strpos($img[$outterKey][$innerKey],"myTarget"); if (!$pos === false) { $i=$outterKey;$j=$innerKey; break 2; } } }
不......你的解决方案听起来合理,如果你知道它总是2层深。 – mpen 2011-02-11 07:48:12
问题是,现在它只有2层深,但我想在可能性思考这个:( – Saikios 2011-02-11 07:51:14