私はすでにこれを研究しましたが、見つかった答えで問題が解決されませんでした。私はすべてのユーザー名項目を 'kk'に変更したいが、後で配列を印刷すると何も変更されていないことがわかる。何が間違っていますか?PHPが多次元配列のアイテムの値を変更する
<?php
$myArray = Array(
0 => Array(
'sender' => kk,
'message' => hhiui,
'timestamp' => '2017-02-04 10:04:57',
'username' => '',
'msgtype' => 0,
'threadid' => 20737047302042017230457
) ,
1 => Array(
'sender' => kk,
'message' => hhiui,
'timestamp' => '2017-02-04 10:04:57',
'username' => '',
'msgtype' => 0,
'threadid' => 20737047302042017230457
) ,
2 => Array(
'sender' => kk,
'message' => hhiui,
'timestamp' => '2017-02-04 10:04:57',
'username' => '',
'msgtype' => '16',
'threadid' => 20737047302042017230457
)
);
foreach($myArray as $value)
{
$value['username'] = "kk";
}
print_r($myArray);
それはちょうど私を与える:
foreach ($myArray as &$value)
{
$value['username'] = "kk";
}
お知らせ&記号:あなたはそのように行っているはずです
Array
(
[0] => Array
(
[sender] => kk
[message] => hhiui
[timestamp] => 2017-02-04 10:04:57
[username] =>
[msgtype] => 0
[threadid] => 2.0737047302042E+22
)
[1] => Array
(
[sender] => kk
[message] => hhiui
[timestamp] => 2017-02-04 10:04:57
[username] =>
[msgtype] => 0
[threadid] => 2.0737047302042E+22
)
[2] => Array
(
[sender] => kk
[message] => hhiui
[timestamp] => 2017-02-04 10:04:57
[username] =>
[msgtype] => 16
[threadid] => 2.0737047302042E+22
)
)
Array
(
[2] => Array
(
[sender] => kk
[message] => hhiui
[timestamp] => 2017-02-04 10:04:57
[username] =>
[msgtype] => 16
[threadid] => 2.0737047302042E+22
)
あなたはそれThaaat's $ myarrayの –