Is it possible to pass in array_column
an array of objects?
I have implemented ArrayAccess interface, but it has no effect.
Should I implement another one?
class Foo implements ArrayAccess {
public $Id, $Title;
public function offsetExists($offset)
{
return isset($this->{$offset});
}
public function offsetGet($offset)
{
return $this->{$offset};
}
public function offsetSet($offset, $value)
{
$this->{$offset} = $value;
}
public function offsetUnset($offset)
{
unset($this->{$offset});
}
}
$object = new Foo();
$object->Id = 1;
$object->Title = 'Test';
$records = array(
$object,
array(
'Id' => 2,
'Title' => 'John'
)
);
var_dump(array_column($records, 'Title')); // array (size=1) 0 => string 'John' (length=4)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…