note 119673 added to class.arrayobject
| From: | jordistcatgmaildotcom | Date: | Sun, 31 Jul 2016 11:04:18 +0000 |
| Subject: | note 119673 added to class.arrayobject | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206137@lists.php.net to get a copy of this message | ||
You can use the array functions on a object of a class that implements ArrayAccess using the
__invoke magic method in this way:
<?php
class ArrayVar implements ArrayAccess
{
private $data = [];
public function __invoke()
{
return $this->data;
}
}
?>
Now you can use like this:
<?php
$arrayar = new ArrayVar();
$arrayar['one'] = 'primer';
$arrayar['two'] = 'segon';
$arrayar['three'] = 'tercer';
$keys = array_keys($arrayar());
var_dump($keys);
// array (size=3)
// 0 => string 'one'
// 1 => string 'two'
// 2 => string 'three'
$diff = array_diff($arrayar(), [ 'two' => 'segon']);
var_dump($diff);
// array (size=2)
// 'one' => string 'primer'
// 'three' => string 'tercer'
?>
----
Server IP: 72.52.91.14
Probable Submitter: 185.38.128.95
----
Manual Page -- http://php.net/manual/en/class.arrayobject.php
Edit -- https://master.php.net/note/edit/119673
Del: integrated -- https://master.php.net/note/delete/119673/integrated
Del: useless -- https://master.php.net/note/delete/119673/useless
Del: bad code -- https://master.php.net/note/delete/119673/bad+code
Del: spam -- https://master.php.net/note/delete/119673/spam
Del: non-english -- https://master.php.net/note/delete/119673/non-english
Del: in docs -- https://master.php.net/note/delete/119673/in+docs
Del: other reasons-- https://master.php.net/note/delete/119673
Reject -- https://master.php.net/note/reject/119673
Search -- https://master.php.net/manage/user-notes.php