note 124855 added to class.ds-collection
| From: | depakin at yisangwu dot com | Date: | Wed, 25 Mar 2020 06:07:15 +0000 |
| Subject: | note 124855 added to class.ds-collection | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214377@lists.php.net to get a copy of this message | ||
// Collection
$collection_a = new \Ds\Vector([1, 2, 3]);
$collection_b = new \Ds\Vector();
var_dump($collection_a, $collection_b);
/*
object(Ds\Vector)[1]
public 0 => int 1
public 1 => int 2
public 2 => int 3
object(Ds\Vector)[2]
*/
//json_encode
var_dump( json_encode($collection_a));
/*
string '[1,2,3]
*/
//count
var_dump(count($collection_a));
/*
int 3
*/
// serialize
var_dump(serialize($collection_a));
/*
string 'C:9:"Ds\Vector":12:{i:1;i:2;i:3;}'
*/
// foreach
foreach ($collection_a as $key => $value) {
echo $key ,'--', $value, PHP_EOL;
}
/*
0--1
1--2
2--3
*/
// clone
$clone = clone($collection_a);
var_dump($clone);
/*
object(Ds\Vector)[1]
public 0 => int 1
public 1 => int 2
public 2 => int 3
*/
// push
$clone->push('aa');
var_dump($clone);
/*
object(Ds\Vector)[3]
public 0 => int 1
public 1 => int 2
public 2 => int 3
public 3 => string 'aa' (length=2)
*/
// isEmpty
var_dump($collection_a->isEmpty(), $collection_b->isEmpty());
/*
boolean false
boolean true
*/
// toArray
var_dump($collection_a->toArray(), $collection_b->toArray());
/*
array (size=3)
0 => int 1
1 => int 2
2 => int 3
array (size=0)
empty
*/
// copy ( void )
//æµ
æ·è´ï¼ shallow copy
$collection_c = $collection_a->copy();
var_dump($collection_c);
/*
object(Ds\Vector)[3]
public 0 => int 1
public 1 => int 2
public 2 => int 3
*/
$collection_c->push(4);
var_dump($collection_a, $collection_c);
/*
object(Ds\Vector)[1]
public 0 => int 1
public 1 => int 2
public 2 => int 3
object(Ds\Vector)[3]
public 0 => int 1
public 1 => int 2
public 2 => int 3
public 3 => int 4
*/
// clear
$collection_a->clear();
$collection_b->clear();
$collection_c->clear();
var_dump($collection_a, $collection_b, $collection_c);
/*
object(Ds\Vector)[1]
object(Ds\Vector)[2]
object(Ds\Vector)[3]
*/
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 183.14.29.155)
----
Manual Page -- http://php.net/manual/en/class.ds-collection.php
Edit -- https://master.php.net/note/edit/124855
Del: integrated -- https://master.php.net/note/delete/124855/integrated
Del: useless -- https://master.php.net/note/delete/124855/useless
Del: bad code -- https://master.php.net/note/delete/124855/bad+code
Del: spam -- https://master.php.net/note/delete/124855/spam
Del: non-english -- https://master.php.net/note/delete/124855/non-english
Del: in docs -- https://master.php.net/note/delete/124855/in+docs
Del: other reasons-- https://master.php.net/note/delete/124855
Reject -- https://master.php.net/note/reject/124855
Search -- https://master.php.net/manage/user-notes.php