php将数组递归,PHP: array_walk_recursive - Manual

usage :

$nd = $newsApp2->dataSources();

//walkArray ($nd, 'walkArray_printKey', 'walkArray_printValue');

// prints the entire array

$x = chaseToPath ($nd, 'RSS_list/English News',false);

walkArray ($x, 'walkArray_printKey', 'walkArray_printValue');

// prints everything under $nd['RSS_list']['English News']

function &chaseToPath (&$wm, $path, $create=false) {

//var_dump ($create); die();

//echo '$wm=

'; var_dump ($wm);echo '
'; //die();

//$path = str_replace ('/', '/d/', $path);

//$path .= '/d';

$nodes = explode ('/', $path);

$chase = &chase ($wm, $nodes, $create);

//echo '$wm=

'; var_dump ($wm);echo '
'; die();

/*

$dbg = array (

'$path' => $path,

'$nodes' => $nodes,

'$wm' => $wm,

'$chase' => $chase

);

echo '$dbg=

'; var_dump ($dbg); echo '
';

*/

//die();

$false = false;

if (good($chase)) {

$arr = &result($chase);

return $arr;

} else return $false;

}

function &chase (&$arr, $indexes, $create=false) {

if (false) {

echo 'sitewide/functions.php --- $arr=

'; var_dump ($arr); echo '
';

echo 'sitewide/functions.php --- $indexes=

'; var_dump ($indexes); echo '
';

echo 'sitewide/functions.php --- $create=

'; var_dump ($create); echo '
';

}

$r = &$arr;

foreach ($indexes as $idx) {

//echo 'sitewide/functions.php --- $idx=

'; var_dump ($idx); var_dump (array_key_exists($idx,$r)); var_dump ($r); echo '
';

if (

is_array($r)

&& (

$create===true

|| array_key_exists($idx,$r)

)

) {

if ($create===true && !array_key_exists($idx,$r)) $r[$idx]=array();

//echo 'sitewide/functions.php --- $idx=

'; var_dump ($idx); echo '
';

$r = &$r[$idx];

} else {

$err = array(

'msg' => 'Could not walk the full tree',

'vars' => array(

'$idx--error'=>$idx,

'$indexes'=>$indexes,

'$arr'=>$arr

)

);

badResult (E_USER_NOTICE, $err);

$ret = false; // BUG #2 squashed

return $ret;

}

}

//echo 'sitewide/functions.php --- $r=

'; var_dump ($r); echo '
';

return goodResult($r);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值