国产精品久久综合亚洲AV,刺激的乱亲小说43部分阅读 ,WWW夜插内射视频网站,护士做爰乱高潮全过程

中山php|最優(yōu)網(wǎng)絡(luò)中山做網(wǎng)站 中山php建站

最優(yōu)良人

2012/12/17 at 20:48

php多維數(shù)組的搜索

1 php搜索多維數(shù)組的鍵值

如下面例子:

$foo[1]['a']['xx'] = 'bar 1';
$foo[1]['b']['xx'] = 'bar 2';
$foo[2]['a']['bb'] = 'bar 3';
$foo[2]['a']['yy'] = 'bar 4';
$foo[3]['c']['dd'] = 'bar 3';
$foo[3]['f']['gg'] = 'bar 3';
$foo['info'][1] = 'bar 5';

如果要查找 bar 3 怎么進(jìn)行查找呢。有三個(gè)結(jié)果,而這三個(gè)結(jié)果都要,看下面的函數(shù):
-------------------------------------------------------------------------------------------------------------------------------
function array_search_re($needle, $haystack, $a=0, $nodes_temp=array()){
global $nodes_found;
$a++;
foreach ($haystack as $key1=>$value1) {
??? $nodes_temp[$a] = $key1;
??? if (is_array($value1)){???
????? array_search_re($needle, $value1, $a, $nodes_temp);
??? }
??? else if ($value1 === $needle){
????? $nodes_found[] = $nodes_temp;
??? }
}
return $nodes_found;
}
---------------------------------------------------------------------------------------------------------------------------------
這個(gè)函數(shù)就可以把上面要查找到的內(nèi)容全部返回出鍵名來(lái)
$result = array_search_re('bar 3', $foo);

print_r($result);

輸出結(jié)果為如下:
Array ( [0] => Array ( [1] => 2 [2] => a [3] => bb )
?????? ?? [1] => Array ( [1] => 3 [2] => c [3] => dd )
?????? ?? [2] => Array ( [1] => 3 [2] => f [3] => gg )
???? ?? )

1 php搜索多維數(shù)組的鍵名

function array_search_key($needle, $haystack){
global $nodes_found;

foreach ($haystack as $key1=>$value1) {
?
?if ($key1=== $needle){
?
??$nodes_found[] = $value1;
???????
?? }
??? if (is_array($value1)){???
????? array_search_key($needle, $value1);
??? }
???
???
}

return $nodes_found;
}
$result = array_search_key('a', $foo);

print_r($result);

輸出結(jié)果為如下:
?

Array
(
??? [0] => Array
??????? (
??????????? [xx] => bar 1
??????? )

??? [1] => Array
??????? (
??????????? [bb] => bar 3
??????? )

??? [2] => Array
??????? (
??????????? [yy] => bar 4
??????? )

)

標(biāo)簽:,
-
寿阳县| 金塔县| 申扎县| 犍为县| 桐乡市| 忻州市| 九龙坡区| 新田县| 五家渠市| 湖北省| 伽师县| 营口市| 黄冈市| 花垣县| 元氏县| 东宁县| 磐安县| 资溪县| 招远市| 霍林郭勒市| 阳新县| 平乐县| 怀化市| 昆山市| 沛县| 岫岩| 罗江县| 漳州市| 锡林浩特市| 武冈市| 惠安县| 顺平县| 贵港市| 正蓝旗| 蒙自县| 铁力市| 临高县| 灵寿县| 兴化市| 临桂县| 云林县|