PHP等效的ColdFusion ValueList()

时间:2019-04-19 20:39:26

标签: php coldfusion

我正在学习PHP,想知道是否有类似ValueList()的PHP?预先谢谢你。

$data = Array
(
[0] => Array
    (
        [id] => 851099
        [title] => Iron Maiden
    )

[1] => Array
    (
        [id] => 852099
        [orgName] => Judas Priest
    )

[2] => Array
    (
        [id] => 861099
        [orgName] => Black Sabbath
    )

)

$valueListTitle = ValueList($data.title)
echo $valueListTitle;

返回以下内容:“铁娘子,犹大牧师,黑色安息日”

1 个答案:

答案 0 :(得分:3)

是的,请检出array_columnimplode以添加逗号。

样品用量:

$data = array(
  ["id" =>1, "title"=>"Iron Maiden"], 
  ["id" =>2, "title"=>"Judas Priest"],
  ["id" =>3, "title"=>"Black Sabbath"],
  ["id" =>4, "title"=>"Deep Purple"],
  ["id" =>5, "title"=>"Rolling Stones"]
);

$valueListTitle = array_column($data, 'title');
$commaSeperated = implode(", ", $valueListTitle);
echo $commaSeperated;

返回以下内容:“铁娘子,犹大牧师,黑安息日,深紫色,滚石乐队”