note 123572 added to class.arrayobject

From: Date: Thu, 31 Jan 2019 07:28:12 +0000
Subject: note 123572 added to class.arrayobject
Groups: php.notes 
Request: Send a blank email to php-notes+get-210149@lists.php.net to get a copy of this message
class RecursiveArrayObject extends \ArrayObject { public function __construct($input = array()) { $data = array(); foreach ($input as $key => $value) { if (is_array($value)) { $value = new self($value); } $data[$key] = $value; } parent::__construct($data, \ArrayObject::ARRAY_AS_PROPS); } } $company = new RecursiveArrayObject(array( 'ceo' => array( 'id' => 1, 'name' => 'tony', 'age' => 36 ), 'coo' => array( 'id' => 2, 'name' => 'matt', 'age' => 35 ), 'cto' => array( 'id' => 3, 'name' => 'james', 'age' => 35 ) )); var_dump($company->cto->name); // string(5) "james" var_dump($company['coo']['name']); // string(4) "matt" ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.142 (proxied: 180.169.131.242) ---- Manual Page -- http://php.net/manual/en/class.arrayobject.php Edit -- https://master.php.net/note/edit/123572 Del: integrated -- https://master.php.net/note/delete/123572/integrated Del: useless -- https://master.php.net/note/delete/123572/useless Del: bad code -- https://master.php.net/note/delete/123572/bad+code Del: spam -- https://master.php.net/note/delete/123572/spam Del: non-english -- https://master.php.net/note/delete/123572/non-english Del: in docs -- https://master.php.net/note/delete/123572/in+docs Del: other reasons-- https://master.php.net/note/delete/123572 Reject -- https://master.php.net/note/reject/123572 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210149) next »