PHP如何使用SplObjectStorage addAll()函数()

SplObjectStorage :: addAll()function是PHP中的内置函数, 用于从另一个存储中添加元素。
语法如下:

void SplObjectStorage::addAll( $value )

【PHP如何使用SplObjectStorage addAll()函数()】参数:该函数接受单个参数$值存放需要导入的存储。
返回值:它不返回任何值。
下面的程序说明了SplObjectStorage :: addAll()PHP中的功能:
程序1:
< ?php// Declare an empty std class $obj = new StdClass; // Declare an empty SplObjectStorage $gfg = new SplObjectStorage(); $gfg [ $obj ] = "lsbin" ; $gfg1 = new SplObjectStorage(); $gfg1 -> addAll( $gfg ); // Print result added to storage object echo $gfg1 [ $obj ] . "\n" ; ?>

输出如下:
lsbin

程式2:
< ?php// Declare an empty std class $obj = new StdClass; $obj2 = new StdClass; // Declare an empty SplObjectStorage $gfg = new SplObjectStorage(); $gfg [ $obj ] = "lsbin" ; $gfg [ $obj2 ] = "lsbin2" ; $gfg1 = new SplObjectStorage(); $gfg1 -> addAll( $gfg ); // Print result with whole object print_r( $gfg1 ); ?>

输出如下:
SplObjectStorage Object ( [storage:SplObjectStorage:private] => Array ( [00000000219a7b260000000055def3bf] => Array ( [obj] => stdClass Object ( )[inf] => lsbin )[00000000219a7b250000000055def3bf] => Array ( [obj] => stdClass Object ( )[inf] => lsbin2 )))

参考: https://www.php.net/manual/en/splobjectstorage.addall.php

    推荐阅读