이 배열이 함수에 의해 반환 될 때 어떻게 배열에서 객체를 가져올 수 있습니까?PHP - 함수가 배열을 반환 할 때 배열에서 객체를 가져 오는 방법은 무엇입니까?
class Item {
private $contents = array('id' => 1);
public function getContents() {
return $contents;
}
}
$i = new Item();
$id = $i->getContents()['id']; // This is not valid?
//I know this is possible, but I was looking for a 1 line method..
$contents = $i->getContents();
$id = $contents['id'];
참조 http://stackoverflow.com/questions/68711/php-can-i-reference-a-single-member-of-an-array-that-is-returned-by-a-function –
' return $ this-> contents; ', 그렇습니까? – deceze