Home > Article > Backend Development > Detailed explanation of how to use ArrayObject in PHP
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.
<span style="font-size: 14px;"><?php //打印全部数组元素$array =array('1'=>'one', '2'=>'two', '3'=>'three');<br/>$arrayobject = new ArrayObject($array);//构造一个ArrayObject对象for($iterator= $arrayobject->getIterator();<br/>//构造一个迭代器 $iterator->valid();//检查是否还含有元素 $iterator->next()){ //指向下个元素 <br/>echo $iterator->key() . ' => ' . $iterator->current() . "\n";//打印数组元素}?><?php <br/>//重置数组指针$arrayobject =new ArrayObject();$arrayobject[] = 'zero';<br/>$arrayobject[] = 'one';$arrayobject[] = 'two';$iterator= $arrayobject->getIterator();<br/>$iterator->next();echo $iterator->key(); // 1$iterator->rewind(); <br/>//重置指针到头部echo $iterator->key(); // 0?><br/></span>
<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>
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!