PHP Standard library Arrayobject

Source: Internet
Author: User

The following are common functions for arrayobject:

Arrayiterator::current (void)//returns the current array element

Arrayiterator::key (void)//Returns the current array key

Arrayiterator::next (void)//refers to the down-number-group element

Arrayiterator::rewind (void)//reset array pointer to head

Arrayiterator::seek ()//Find a location in an array

Arrayiterator::valid ()//check if the array also contains other elements

Arrayobject::append ()//Add new element

Arrayobject::__construct ()//construct a new Array object

Arrayobject::count ()//Returns the number of elements in the iterator

Arrayobject::getiterator ()//construct a new iterator from an array object

Arrayobject::offsetexists (mixed index)//determine if the submitted value exists

Arrayobject::offsetget ()//Specify name to get the value

Arrayobject::offsetset ()//Modify the value of the specified name

Arrayobject::offsetunset ()//delete data

Example 1: Print all elements of an array

<?php
$array = Array (' 1 ' = ' one ',
' 2 ' = ' both ',
' 3 ' = ' three ');

$arrayobject = new Arrayobject ($array); Constructs a Arrayobject object

for ($iterator = $arrayobject->getiterator ();//Constructs an iterator
$iterator->valid ();//Check if the element is still included
$iterator->next ()) {//points to the next element

echo $iterator->key (). ' = '. $iterator->current (). "\ n";//print array elements
}
?>
Example 2: Resetting an array pointer

<?php
$arrayobject = new Arrayobject ();

$arrayobject [] = ' zero ';
$arrayobject [] = ' one ';
$arrayobject [] = ' both ';

$iterator = $arrayobject->getiterator ();

$iterator->next ();
echo $iterator->key (); 1

$iterator->rewind (); Reset the pointer to the head
echo $iterator->key (); 0
?>

PHP Standard library Arrayobject

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.