拆分数组元素php

时间:2018-04-08 13:09:05

标签: php mysql arrays

示例

$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] =&gt;文件;等...... 提前谢谢。

1 个答案:

答案 0 :(得分:0)

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

$myArray = [];

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