如何从MySQL数据库中的while循环中提取数组值

时间:2019-05-01 08:11:27

标签: php arrays

如何在数组中获取值并在while循环中提取 下面写一些行代码,请帮助

$sql = "SELECT * FROM Table WHERE id=1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$view = $result->fetch_assoc() 
$arrrrrrr = $view['quiz_que'];
    $arraysss = [$arrrrrrr];                
    print_r($arraysss);
  

Ourput数组([0] => A1,F2,3,4,S5,6,7,816,17)

我想要什么

$a = [1, 2, 3, 4];
print_r($a);
  

输出数组([0] => 1 [1] => 2 [2] => 3 [3] => 4)

1 个答案:

答案 0 :(得分:0)

尝试一下

$arrrrrrr = $view['quiz_que'];//A1,F2,3,4,S5,6,7,816,17
$quiz_queArray = explode(',',$arrrrrrr);
echo'<pre>';print_r($quiz_queArray);die;

输出:

Array
(
    [0] => A1
    [1] => F2
    [2] => 3
    [3] => 4
    [4] => S5
    [5] => 6
    [6] => 7
    [7] => 816
    [8] => 17
)