一直对数组的一个问题比较困惑

帖子列表 发布于 2013/09/03 10:35
阅读 199
收藏 0
PHP
foreach($channelsTop as $chid => $channel){
    if(is_array($channel['Products'])){
        foreach($channel['Products'] as $key => $pid) {
            $channelsTop[$chid]['Products'][$key] = $pid . $chid;
        }

        print_r($channelsTop[$chid]['Products']);die; // 可以append
    }
}

foreach($channelsTop as $chid => $channel){
    if(is_array($channel['Products'])){
        foreach($channel['Products'] as $key => $pid) {
            $channelsTop[$chid]['Products'][$key] = $pid . $chid;
        }

        print_r($channel['Products']);die; // 不可以append
    }
}

这样怎么解决? 有啥比第一种访问方式更好的方法?
加载中
0
oxsicn
oxsicn
能提供以下数组吗
苏生不惑
苏生不惑
同问
0
酒逍遥
酒逍遥
数组引用啊 
foreach($channelsTop as $chid => &$channel){
    if(is_array($channel['Products'])){
        foreach($channel['Products'] as $key => &$pid) {
            $pid.= $chid;
        }
        print_r($channel['Products']);die; // 可以append
    }
}
0
mark35
mark35
foreach ($channelsTop as $chid => & $channel)
{
    if (is_array($channel['Products']))
    {
        foreach ($channel['Products'] as & $pid) {
            $pid = $pid . $chid;
        }

//        print_r($channelsTop[$chid]['Products']);die; 
//        print_r($channel['Products']);die;
    }
}
unset($channel, $pid);
php5



返回顶部
顶部