肉色超薄丝袜脚交一区二区,香蕉久久av一区二区三区,男人进入女人下部视频,被几个人强的好爽小说

中山php|最優網絡中山做網站 中山php建站

最優良人

2012/12/17 at 20:48

php多維數組的搜索

1 php搜索多維數組的鍵值

如下面例子:

$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 怎么進行查找呢。有三個結果,而這三個結果都要,看下面的函數:
-------------------------------------------------------------------------------------------------------------------------------
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;
}
---------------------------------------------------------------------------------------------------------------------------------
這個函數就可以把上面要查找到的內容全部返回出鍵名來
$result = array_search_re('bar 3', $foo);

print_r($result);

輸出結果為如下:
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搜索多維數組的鍵名

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);

輸出結果為如下:
?

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

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

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

)

標簽:,
-
主站蜘蛛池模板: 高淳县| 黄浦区| 广灵县| 抚远县| 嘉峪关市| 云霄县| 长春市| 哈巴河县| 阿克苏市| 泰来县| 庆安县| 新巴尔虎右旗| 灵石县| 德惠市| 德钦县| 丘北县| 黄平县| 凤山县| 达日县| 青神县| 广东省| 分宜县| 镇赉县| 崇礼县| 临泽县| 来宾市| 成安县| 左贡县| 横山县| 田东县| 庆元县| 桃园市| 陆川县| 宿迁市| 彰化县| 牡丹江市| 甘孜县| 蒙城县| 景宁| 商城县| 博野县|