我当前的项目由多维数组组成,其中包含日期和一些文本内容。
我已经在我的项目中使用了普通数组,array_push用于将元素插入数组。 不,我被困在多维数组中,我不知道如何插入和显示多维数组(初学者到多维数组)。
我从StackOverflow本身找到了很多结果,但没有一个对我有帮助。 我创建了一个这样的多维数组
$complaints = array(
$each_complaints => array(
"date" => "",
"text" => ""
)
);
然后我想在 MySQL 结果循环中将数据添加到这个数组中
<?php foreach($query_56 as $notes):
// eg: array_push " $notes->date , $notes->corresponding_text "
endforeach; ?>
我想像这样显示数组
array[date][text]=> [2014-11-18] [1st complaint]
array[date][text]=> [2015-01-15] [2nd complaint]
我怎么能做到这一点,我乞求多二元数组。
任何帮助将不胜感激。
<?php foreach($query_56 as $key=>$notes):
$each_complaints[$key]["date"] = $notes->date;
$each_complaints[$key]["text"] = $notes->corresponding_text ;
endforeach;
echo "<pre>";print_r($each_complaints);
?>
**Output :**
(
[0] => Array
(
[date] => 01-11-2014
[text] => rrrrrr
)
[1] => Array
(
[date] => 02-11-2014
[text] => fffff
)
[2] => Array
(
[date] => 03-11-2014
[text] => ddddd
)
)