dqt20140129 2014-10-13 18:43
浏览 3271
已采纳

警告:explode()期望参数2为字符串,给定[闭合]数组

The Script:

<?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);

?>

I have the following entry in one row of the column "some_text_id":

164, 165, 166

I am looking to "explode" this by the comma and have it stored in an array, so I can select the numbers individually, e.g.:

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

Though I am getting the following error message:

Warning: explode() expects parameter 2 to be string, array given in ... (points to the explode function)

Any suggestions on how to do this?

  • 写回答

1条回答 默认 最新

  • dpnw86361 2014-10-13 18:45
    关注

    Skip the part where you put the database results into an array. It's completely unnecessary:

    <?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);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊