【问题标题】:Splitting array elements php拆分数组元素php
【发布时间】:2018-09-17 23:32:21
【问题描述】:

示例

$query = mysqli_query($db, "select name from documentation");
while ($row = mysqli_fetch_assoc($query)) {
print_r($row); echo "<br />";
}   

Array ( [name] => Orders ) 
Array ( [name] => Documents ) 
Array ( [name] => Letters ) 

问题。如何拆分数组元素?
例如,$row[0] 将是 Orders; $row[1] => 文件;等等...
提前致谢。

【问题讨论】:

  • 对于索引数组生成,使用$output[] = $row['name'];。这是一个研究不足的问题。
  • 一开始就不是问题。

标签: php mysql arrays


【解决方案1】:

您可以在每次迭代中初始化一个数组并为其添加项目。

$myArray = [];

$query = mysqli_query($db, "select name from documentation");
while ($row = mysqli_fetch_assoc($query)) {
    //Print what you need to print
    $myArray[]=$row['name'];
}   

【讨论】:

    猜你喜欢
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多