note 50811 added to function.arrayobject-construct

From: Date: Thu, 10 Mar 2005 16:17:39 +0000
Subject: note 50811 added to function.arrayobject-construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-86209@lists.php.net to get a copy of this message
Esta clase crea un objeto con un array pasado como parámetro al constructor. Este objeto devuelto permite manejar el array mediante los metodos count(), getIterator(), offsetExists(), offsetGet(), offsetSet(), offsetUnset() <?php $array=array(1=>'uno',2=>'dos',3=>'tres'); $objeto=new ArrayObject($array); echo $objeto->count().'<br>'; /*Imprime 3 que es el nº de elementos del array*/ $i=$objeto->getIterator(); while($i->valid()){ echo $i->current().'<br>';/*escribe los contenidos de $objeto*/ echo $objeto->offsetGet($i->key()).'<br>';/*tambien lo hace*/ $i->next(); } $objeto->offsetSet(1,'uno-2'); echo $objeto->offsetGet(1).'<br>';/*escribe 'uno-2'*/ $objeto->offsetUnset(1); echo $objeto->offsetGet(1).'-<br>';/*no existe -> NULL*/ ?> esto ofrece a la salida: ----------------------- 3 uno uno dos dos tres tres uno-2 - --------------------- ---- Manual Page -- http://www.php.net/manual/en/function.arrayobject-construct.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50811 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50811&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50811&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50811&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50811&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50811&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50811&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86209) next »