文字

ArrayObject::append

(PHP 5 >= 5.0.0)

ArrayObject::append追加新的值作为最后一个元素。

说明

public void ArrayObject::append ( mixed $value )

追加新的值作为最后一个元素。

Note:

当 ArrayObject 从 object 初始化时不能调用此方法。使用 ArrayObject::offsetSet() 代替。

参数

value

将要被追加的值

返回值

没有返回值。

范例

Example #1 ArrayObject::append() 例子

<?php
$arrayobj 
= new  ArrayObject (array( 'first' , 'second' , 'third' ));
$arrayobj -> append ( 'fourth' );
$arrayobj -> append (array( 'five' 'six' ));
var_dump ( $arrayobj );
?>

以上例程会输出:

object(ArrayObject)#1 (5) {
  [0]=>
  string(5) "first"
  [1]=>
  string(6) "second"
  [2]=>
  string(5) "third"
  [3]=>
  string(6) "fourth"
  [4]=>
  array(2) {
    [0]=>
    string(4) "five"
    [1]=>
    string(3) "six"
  }
}

参见

  • ArrayObject::offsetSet() - 为指定索引设定新的值

用户评论:

[#1] c dot 1 at smithies dot org [2009-11-25 09:56:26]

This member function is implemented as follows:

<?php
class ArrayObject  {
  
// ...
  
public function append($v) {
    return 
$this->offsetSet(NULL$v);
  }
  
// ...
}
?>

上一篇: 下一篇: