Detailed explanation of how to use ArrayObject in PHP

小云云
Release: 2023-03-20 22:18:02
Original
4147 people have browsed it

ArrayObject converts an array into an array object. This article mainly shares with you the instructions for using ArrayObject. I hope it can help you.

Code example

<span style="font-size: 14px;"><?php  //打印全部数组元素$array =array(&#39;1&#39;=>&#39;one&#39;, &#39;2&#39;=>&#39;two&#39;, &#39;3&#39;=>&#39;three&#39;);<br/>$arrayobject = new ArrayObject($array);//构造一个ArrayObject对象for($iterator= $arrayobject->getIterator();<br/>//构造一个迭代器    $iterator->valid();//检查是否还含有元素    $iterator->next()){ //指向下个元素    <br/>echo $iterator->key() . &#39; => &#39; . $iterator->current() . "\n";//打印数组元素}?><?php   <br/>//重置数组指针$arrayobject =new ArrayObject();$arrayobject[] = &#39;zero&#39;;<br/>$arrayobject[] = &#39;one&#39;;$arrayobject[] = &#39;two&#39;;$iterator= $arrayobject->getIterator();<br/>$iterator->next();echo $iterator->key(); // 1$iterator->rewind(); <br/>//重置指针到头部echo $iterator->key(); // 0?><br/></span>
Copy after login

Commonly used functions of ArrayObject

<span style="font-size: 14px;">ArrayIterator::current( void ) <br/>//返回当前数组元素ArrayIterator::key(void) <br/>//返回当前数组keyArrayIterator::next (void)<br/>//指向下个数组元素ArrayIterator::rewind(void )<br/>//重置数组指针到头ArrayIterator::seek()<br/>//查找数组中某一位置ArrayIterator::valid()<br/>//检查数组是否还包含其他元素ArrayObject::append()<br/>//添加新元素ArrayObject::__construct()<br/>//构造一个新的数组对象ArrayObject::count()<br/>//返回迭代器中元素个数ArrayObject::getIterator()<br/>//从一个数组对象构造一个新迭代器ArrayObject::offsetExists(mixed index )<br/>//判断提交的值是否存在ArrayObject::offsetGet()<br/>//指定 name 获取值ArrayObject::offsetSet()<br/>//修改指定 name 的值ArrayObject::offsetUnset()<br/>//删除数据<br/></span>
Copy after login

Related recommendations:

Application example code of ArrayObject extension

The above is the detailed content of Detailed explanation of how to use ArrayObject in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template