当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP SplObjectStorage addAll()用法及代码示例


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

用法:

void SplObjectStorage::addAll( $value )

参数:该函数接受单个参数$value,该参数保存需要导入的存储。


返回值:它不返回任何值。

以下示例程序旨在说明PHP中的SplObjectStorage::addAll()函数:

程序1:

<?php 
  
// Declare an empty std class 
$obj = new StdClass; 
  
// Declare an empty SplObjectStorage 
$gfg = new SplObjectStorage(); 
  
$gfg[$obj] = "GeeksforGeeks"; 
  
$gfg1 = new SplObjectStorage(); 
$gfg1->addAll($gfg); 
  
// Print result added to storage object 
echo $gfg1[$obj] . "\n"; 
?>
输出:
GeeksforGeeks

程序2:

<?php 
  
// Declare an empty std class 
$obj = new StdClass; 
$obj2 = new StdClass; 
  
// Declare an empty SplObjectStorage 
$gfg = new SplObjectStorage(); 
$gfg[$obj] = "GeeksforGeeks"; 
$gfg[$obj2] = "GeeksforGeeks2"; 
  
$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] => GeeksforGeeks
                )

            [00000000219a7b250000000055def3bf] => Array
                (
                    [obj] => stdClass Object
                        (
                        )

                    [inf] => GeeksforGeeks2
                )

        )

)

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



相关用法


注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage addAll() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。