php 數組處理的疑惑
我想大声告诉你
我想大声告诉你 2017-07-01 09:11:51
0
2
725
foreach ($good_info as $key => &$val) {
            $val['g_num'] = $vv[$key];
            $val['ware_Beizu'] = $bb[$key];

        }
[7]=>
  array(15) {
    ["id"]=>
    string(4) "1170"
    ["g_name"]=>
    string(12) "日本豆腐"
    ["g_images"]=>
    string(72) "http://xlddc.zkd.com/Public/Uploads/goods/2017-06-29/595450d5db86a.jpg"
    ["g_price"]=>
    string(1) "0"
    ["g_attr"]=>
    string(7) "90g/根"
    ["g_cd"]=>
    string(6) "中国"
    ["g_desc"]=>
    string(0) ""
    ["g_count"]=>
    string(3) "998"
    ["g_sum"]=>
    string(1) "1"
    ["g_cat"]=>
    string(3) "878"
    ["is_on_sale"]=>
    string(1) "1"
    ["g_sn"]=>
    string(5) "13033"
    ["g_cont"]=>
    NULL
    ["g_num"]=>
    string(1) "1"
    ["ware_Beizu"]=>
    string(12) "日本豆腐"
  }
  [8]=>
  &array(15) {
    ["id"]=>
    string(4) "1175"
    ["g_name"]=>
    string(9) "咸鸭蛋"
    ["g_images"]=>
    string(72) "http://xlddc.zkd.com/Public/Uploads/goods/2017-06-29/595456e6e0c73.jpg"
    ["g_price"]=>
    string(1) "0"
    ["g_attr"]=>
    string(3) "只"
    ["g_cd"]=>
    string(6) "中国"
    ["g_desc"]=>
    string(0) ""
    ["g_count"]=>
    string(3) "997"
    ["g_sum"]=>
    string(1) "2"
    ["g_cat"]=>
    string(3) "879"
    ["is_on_sale"]=>
    string(1) "1"
    ["g_sn"]=>
    string(10) "0401002002"
    ["g_cont"]=>
    NULL
    ["g_num"]=>
    string(1) "1"
    ["ware_Beizu"]=>
    string(9) "咸鸭蛋"
  }
}

第八條 哪裡怎麼多了個& 怎麼去掉&尼?

我想大声告诉你
我想大声告诉你

全部回覆(2)
给我你的怀抱

解決方案是永遠不要用&

或老實按照官網的指示,用unset解除引用

<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>

參考(之前提問): /q/10...
參考2(用&導致的「異常」行為): https://3v4l.org/hlJda

学习ing

foreach ($good_info as $key => &$val) {
這個 & 是什麼意思呢

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板