- array_column: documentation ( source)
- implode: documentation ( source)
<?php
class Artist implements ArrayAccess {
public $artist_name;
function __construct($name) {
$this->artist_name = $name;
}
function offsetGet($name) {
return $this->$name;
}
function offsetExists($name) {
return isset($this->$name);
}
function offsetSet($name, $value) {
$this->$name = $value;
}
function offsetUnset($name) {
unset($this->$name);
}
}
$artists = array(
new Artist('Dali'),
new Artist('Picasso'),
new Artist('Titian'),
);
echo implode(', ', array_column($artists, 'artist_name')), "\n";
/*****/