A detailed description of how arrayobject is used in PHP

Source: Internet
Author: User
Arrayobject is to convert an array of arrays of objects, this article mainly to share with you arrayobject instructions, I hope to help everyone.

code example

<?php  //Print all array elements $array =array (' 1 ' = ' one ', ' 2 ' + ', ' 3 ' = ' three ');
$arrayobject = new Arrayobject ($array);//Constructs a Arrayobject object for ($iterator = $arrayobject->getiterator ();
Constructs an iterator $iterator->valid ();//Checks if there are elements $iterator->next ()) {//points to the next element
echo $iterator->key (). ' = '. $iterator->current (). "\ n";//print array element}?><?php
Resets the array pointer $arrayobject =new arrayobject (); $arrayobject [] = ' zero ';
$arrayobject [] = ' one '; $arrayobject [] = ' one '; $iterator = $arrayobject->getiterator ();

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

Common functions of Arrayobject

arrayiterator::current (void) 
// Returns the current array element arrayiterator::key (void)
//Returns the current array keyarrayiterator::next (void)
//points to the next group element Arrayiterator::rewind ( void)
//reset array pointer to head arrayiterator::seek ()
//Find a location in the array arrayiterator::valid ()
//Check whether the array also contains other elements Arrayobject:: Append ()
//Add new Element Arrayobject::__construct ()
//construct a new Array object Arrayobject::count ()
//Return the number of elements in the iterator Arrayobject:: Getiterator ()
//Constructs a new iterator from an array object Arrayobject::offsetexists (mixed index)
//Determines whether the committed value exists Arrayobject::offsetget (
//Specify name to get the value Arrayobject::offsetset ()
//Modify the value of the specified name Arrayobject::offsetunset ()
//delete data

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.