I'm learning PHP and was wondering if there some like ValueList() for PHP? Thank you in advance.

$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;

which return this: "Iron Maiden, Judas Priest, Black Sabbath"

1 Answers

3
nico On Best Solutions

Yes, check out array_column and implode to add commas.

Sample usage:

$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;

which return this: "Iron Maiden, Judas Priest, Black Sabbath, Deep Purple, Rolling Stones"