0
我有一个准备语句来从数据库中绘制信息。有三个从数据库中提取的信息字段和未知数量的行。在一个while循环中创建一个2D PHP数组
我有一个'while'循环来定义从每行获得的信息应该发生什么。我想为每行的3个信息字段创建一个数组,然后为所有这些数组(即2D数组)创建一个数组。
这里是我到目前为止的代码:
$bArray = [];
$bList = $mysqli->prepare('SELECT blog_title,blog_date,blog_id FROM cms_blog');
$bList->execute();
$bList->bind_result($bListTitle,$bListDate,$bListId);
while ($bList->fetch()) {
$bArray['bTitle']=$bListTitle;
$bArray['bDate']=$bListDate;
$bArray['bId']=$bListId;
}
我想数组看起来像这样一次完整:
Array (
Array (
[blogTitle] => First title
[blogDate] => First date
[blogId] => First ID
)
Array (
[blogTitle] => Second title
[blogDate] => Second date
[blogId] => Second ID
)
)
有没有写这个办法?我只需要内部数组的密钥对。
作品完美的感谢!只是出于好奇,最好是声明数组变量像'$ bArray = [];'或'$ bArray = array();'? – Coop
对不起,我不知道什么更好。我使用数组(),它的工作原理;) – KikoV