public function natsort() { parent::natsort(); return $this; }
<?php $data = array('mela', 'pera', 'bananaa', 'arancia'); $object = new ArrayObject($data); echo sprintf('L\'array contiene %d elementi', $object->count()), PHP_EOL; $object->natsort(); echo 'Elemento con indice 0: ', $object[0], PHP_EOL; foreach ($object as $value) { echo $value, PHP_EOL; } class Persona { public $nome; public $cognome; public $telefono; } $persona = new Persona(); $persona->cognome = 'Rossi'; $persona->nome = 'Mario'; $persona->telefono = '223344'; $obj_array = new ArrayObject($persona); echo sprintf('L\'oggetto persona contiene %d elementi', $obj_array->count()), PHP_EOL; $obj_array->natsort(); foreach ($obj_array->getIterator() as $name => $value) { echo $name . ': ' . $value, PHP_EOL; }
<?php /* Prototype : int ArrayObject::natsort() * Description: proto int ArrayIterator::natsort() Sort the entries by values using "natural order" algorithm. * Source code: ext/spl/spl_array.c * Alias to functions: */ echo "*** Testing ArrayObject::natsort() : basic functionality ***\n"; $ao1 = new ArrayObject(array('boo10', 'boo1', 'boo2', 'boo22', 'BOO5')); $ao2 = new ArrayObject(array('a' => 'boo10', 'b' => 'boo1', 'c' => 'boo2', 'd' => 'boo22', 'e' => 'BOO5')); var_dump($ao1->natsort()); var_dump($ao1); var_dump($ao2->natsort('blah')); var_dump($ao2); ?> ===DONE===
<?php $dados = ['salmão', 'tilápia', 'sardinha', 'badejo', 'pescada', 'dourado', 'corvina', 'cavala', 'bagre']; $objarray = new ArrayObject($dados); $objarray->append('bacalhau'); print 'Posição 2: ' . $objarray->offsetGet(2) . '<br>' . PHP_EOL; $objarray->offsetSet(2, 'linguado'); print 'Posição 2: ' . $objarray->offsetGet(2) . '<br>' . PHP_EOL; $objarray->offsetUnset(4); if ($objarray->offsetExists(10)) { echo 'Posição 10 encontrada' . '<br>' . PHP_EOL; } else { echo 'Posição 10 não encontrada' . '<br>' . PHP_EOL; } print 'Total: ' . $objarray->count(); $objarray[] = 'atum'; $objarray->natsort(); print '<br>' . PHP_EOL; foreach ($objarray as $item) { print 'Item: ' . $item . '<br>' . PHP_EOL; } print $objarray->serialize();
public function natsort() { $this->lazyLoadArray(); parent::natsort(); }
/** * Implementation of ArrayObject::natsort(). * * This method implements a sort algorithm that orders alphanumeric strings * in the way a human being would while maintaining key/value associations. * This is described as a "natural ordering". An example of the difference * between this algorithm and the regular computer string sorting algorithms * (used in ArrayObject::asort) method can be seen in the example below. * * No value is returned. */ public function natsort() { $this->arrayObject->natsort(); }