Php 将每行读入数组
我有点卡住了,我能把每一行读入一个数组,但它是一个关联数组,但我不想要,我想要一个普通数组Php 将每行读入数组,php,mysql,arrays,Php,Mysql,Arrays,我有点卡住了,我能把每一行读入一个数组,但它是一个关联数组,但我不想要,我想要一个普通数组(数组=['2','3','4']) 另外,我的表只有一列,所以应该更简单 这是我的密码 var\u dump给了我: array(3) { [0]=> array(1) { [0]=> string(44) "0Av5k2xcMXwlmdEV6NXRZZnJXS2s4T3pSNzViREN6dHc" } [1]=> array(1) { [0]=> string(4
(数组=['2','3','4'])
另外,我的表只有一列,所以应该更简单
这是我的密码
var\u dump
给了我:
array(3) { [0]=> array(1) { [0]=> string(44)
"0Av5k2xcMXwlmdEV6NXRZZnJXS2s4T3pSNzViREN6dHc" } [1]=> array(1) { [0]=> string(44)
"0Av5k2xcMXwlmdDhTV2NxbXpqTmFyTUNxS0VkalZTSnc" } [2]=> array(1) { [0]=> string(44)
"0Av5k2xcMXwlmdDdhdVpMenBTZTltY2VwSXE0NnNmWWc" } }
这说明它是一个关联数组
$fileList = getLiveList();
var_dump($fileList);
function getLiveList(){
$query = "SELECT id FROM livelist";
$result = mysql_query($query); // This line executes the MySQL query that you typed above
$array = []; // make a new array to hold all your data
$index = 0;
while($row = mysql_fetch_row($result)) // loop to give you the data in an associative array so you can use it however.
{
$array[$index] = $row;
$index++;
}
return $array;
}
mysql\u查询返回索引数组和关联数组 根据需要使用mysql\u fetch\u数组或mysql\u fetch\u assoc 哦,您应该使用mysqli函数:-)只需从第行获取
id
(第一个元素)
$array = []; // make a new array to hold all your data
while($row = mysql_fetch_row($result)) // loop to give you the data in an associative array so you can use it however.
{
$array[] = $row[0];
}
return $array;
注意:。它们不再得到维护。看到了吗?相反,学习,并使用,或-将帮助您决定哪一个。如果您选择PDO,.在while循环中不需要$index:您只需使用$array[]=$row[0]
$fileList = getLiveList();
var_dump($fileList);
function getLiveList(){
$query = "SELECT id FROM livelist";
$result = mysql_query($query); // This line executes the MySQL query that you typed above
$array = []; // make a new array to hold all your data
while($row = mysql_fetch_row($result)) // loop to give you the data in an associative array so you can use it however.
{
$array[] = $row[0];
}
return $array;
}