Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的数组中有超过 10 个值。
我想用逗号分隔它。
所以我使用了这段代码
echo implode(",", $array);
有人能告诉我如何限制这些值吗?我只需要前三个值
先切片数组
$newArray = array_slice($array, 0, 3); echo implode(',', $newArray);
使用array_slice:
array_slice
$slicedArray = array_slice($array, 0, 3); $input=implode(",", $slicedArray);