php 警告:explode() 期望参数 2 是字符串,给定数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26346784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: explode() expects parameter 2 to be string, array given
提问by ftxn
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":
我在“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)
警告:explode() 期望参数 2 是字符串,数组在 ...(指向爆炸函数)
Any suggestions on how to do this?
关于如何做到这一点的任何建议?
回答by John Conde
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);
?>