當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。