当前位置:  首页>> 技术小册>> PHP合辑5-SPL标准库

SplDoublyLinkedList::add()函数是PHP中的内置函数,用于在给定索引处添加新值。

语法:

void SplDoublyLinkedList::add( index,newval )
参数:它包含上面提到的两个参数,并如下所示:

index:它保存新元素要插入的索引值。newval:它保存要插入或添加的元素。
返回值:它不返回任何值。

示例:

  1. <?php
  2. // Declare an empty SplDoublyLinkedList
  3. $list = new \SplDoublyLinkedList;
  4. // Use SplDoublyLinkedList::add() function to
  5. // add elements to the SplDoublyLinkedList
  6. $list->add(0, 1);
  7. $list->add(1, "Geeks");
  8. $list->add(2, "G");
  9. $list->add(3, 10);
  10. print_r($list);
  11. ?>

output:

  1. SplDoublyLinkedList Object
  2. (
  3. [flags:SplDoublyLinkedList:private] => 0
  4. [dllist:SplDoublyLinkedList:private] => Array
  5. (
  6. [0] => 1
  7. [1] => Geeks
  8. [2] => G
  9. [3] => 10
  10. )
  11. )