-
ABOUTYOU
假设它应该是一个 JSON 字符串:$vals = collect(json_decode($demo))->pluck('name')->join(',');如果这只是您描述返回数组或对象的数组(转换为 JSON)时的外观:$vals = collect($demo)->pluck('name')->join(',');使用集合来提供帮助只是解决此问题的一种方法。
-
缥缈止盈
首先$demo = [{"value":"red"},{"value":"green"},{"value":"blue"}]是无效的 PHP 代码。我假设它是一个 JSON 字符串,然后你可以这样做:$demo = '[{"value":"red"},{"value":"green"},{"value":"blue"}]';$json = json_decode($demo);$data = array_map(function ($item) { return $item->value;}, $json); // This is now array of values, ['red', 'green', 'blue']
-
慕无忌1623718
首先$demo = [{"value":"red"},{"value":"green"},{"value":"blue"}]是无效的 PHP 代码。我假设它是一个 JSON 字符串,然后你可以这样做:$demo = '[{"value":"red"},{"value":"green"},{"value":"blue"}]';$json = json_decode($demo);$data = array_map(function ($item) { return $item->value;}, $json); // This is now array of values, ['red', 'green', 'blue']
-
喵喵时光机
使用内爆!文档: https: //www.php.net/manual/en/function.implode.php$array = array('1'=>'red', '2'=>'green', '3'=>'blue');echo implode(",", $array);// output -> red,green,blue我的测试:uvulpos@Timvpos:/etc/apache2/sites-available$ php -aInteractive mode enabledphp > $array = array('1'=>'red', '2'=>'green', '3'=>'blue');php > print_r($array);Array( [1] => red [2] => green [3] => blue)php > echo implode(",", $array);red,green,bluephp >