我有以下代码和输出。在循环注释#2被注释#1的数据覆盖后,这怎么可能?
<?php
echo "<pre>".print_r($notes, true)."</pre>";
foreach($notes as $k=>$note){
// nothing here
}
echo "<pre>".print_r($notes, true)."</pre>";
?>
输出结果为:
Array
(
[3] => Array
(
[created] => 2015-11-17 13:22:19
[user] => 249340
[text] => test
[important] =>
[author] => Joe
)
[2] => Array
(
[created] => 2015-11-17 12:52:44
[user] => 249340
[text] => He is Spanish
[important] =>
[author] => Bill
)
[1] => Array
(
[created] => 2015-11-17 12:52:28
[user] => 249340
[text] => He is a clown
[important] => 1
[firstname] => Bill
)
)
Array
(
[3] => Array
(
[created] => 2015-11-17 13:22:19
[user] => 249340
[text] => test
[important] =>
[author] => Joe
)
[2] => Array
(
[created] => 2015-11-17 12:52:28
[user] => 249340
[text] => He is a clown
[important] => 1
[firstname] => Bill
)
[1] => Array
(
[created] => 2015-11-17 12:52:28
[user] => 249340
[text] => He is a clown
[important] => 1
[author] => Bill
)
)
定义$notes
的代码:
<?php
$query = "SELECT * FROM notes WHERE user=249340";
$select = $mysqli->query($query);
while ($row = $select->fetch_assoc()) {
$notes[$row['id']] = array_filter($row,function($var){return
!is_null($var);});
unset($notes[$row['id']]["id"]);
}
$select->free();
if(!count($notes)) {
$notes = NULL;
}
krsort($notes);
?>