php - 有没有办法从单独的行创建数组?

标签 php arrays sorting

我有以下代码:

//turn items into an array
$item_array = array('football','basketball','tennis-ball');

//implode items, turn into string
//result for this string is football','basketball','tennis-ball
$item_implode = join("','", $item_array);

//declare an overall array for result
$product_items = array();

$productList = array();
$result = $con->query("select * from table_products where Name IN ('$item_implode')");

假设我想要将 20 个项目插入到数组中(而不是代码中的 3 个) -

就我个人而言,如果我可以将每个项目插入到自己的行中(例如,一行将取代逗号 , 的角色,而不是在同一行中,对我来说会更容易,因为它会很长并且超出屏幕。

例如,有没有办法使数组像这样:

$item_array = array(
'football'
'basketball'
'tennis-ball'
);

最佳答案

我不太确定你在这里要做什么,无论哪种方式显示数组都没有任何可能性,你只能将数组用作数组,但它必须有逗号分隔值,否则你会收到错误。

http://www.w3schools.com/php/php_arrays.asp

关于php - 有没有办法从单独的行创建数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34589357/

相关文章:

php - wordpress 显示之前未显示的随机帖子

java - 尝试将二维数组顺时针旋转 90 度,但它是逆时针旋转

C++:使用STL排序对不同列上的二维整数数组进行排序的时间复杂度

php - file_get_contents 接收 cookie

php - 自 php 5.4 起链接不起作用

php - 通过 php 确认对 sql 数据库的更改和添加?

php - android - 在 mysql 上使用 foreach 显示数据数组

c - C 中的数组指针问题 - 数组只包含最后一个值

javascript排序函数两个字段(条件)

Python 函数基于参数进行排序和操作