警告:explode()期望参数2是字符串,给定数组

时间:2014-10-13 18:43:51

标签: php arrays explode

剧本:

<?php

    $tqs = "SELECT * FROM `table_two`";
    $tqr = mysqli_query($dbc, $tqs);
    $row = mysqli_fetch_assoc($tqr);
    $thearray[] = $row['some_text_id'];

    // Prints e.g.: Array ( [0] => 164, 165, 166 )
    print_r($thearray);

    echo "<br/><br/>";
    echo "<br/><br/>";

    $thearray = explode(", ", $thearray);
    print_r($thearray);

?>

我在“some_text_id”列的一行中有以下条目:

164, 165, 166

我希望用逗号“爆炸”它并将它存储在一个数组中,所以我可以单独选择数字,例如:

myarray[0], myarray[1], myarray[2]

虽然我收到以下错误消息:

  

警告:explode()期望参数2为字符串,数组以...给出(指向爆炸函数)

有关如何执行此操作的任何建议吗?

1 个答案:

答案 0 :(得分:6)

跳过将数据库结果放入数组的部分。这完全没必要:

<?php

    $tqs = "SELECT * FROM `table_two`";
    $tqr = mysqli_query($dbc, $tqs);
    $row = mysqli_fetch_assoc($tqr);

    // Prints e.g.: 164, 165, 166
    print_r($row['some_text_id']);

    echo "<br/><br/>";
    echo "<br/><br/>";

    $thearray = explode(", ", $row['some_text_id']);
    print_r($thearray);

?>