本文整理汇总了PHP中ArrayObject::natsort方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayObject::natsort方法的具体用法?PHP ArrayObject::natsort怎么用?PHP ArrayObject::natsort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayObject
的用法示例。
在下文中一共展示了ArrayObject::natsort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: natsort
public function natsort()
{
parent::natsort();
return $this;
}
示例2: sprintf
<?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;
}
示例3: ArrayObject
<?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===
示例4: ArrayObject
<?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();
示例5: natsort
public function natsort()
{
$this->lazyLoadArray();
parent::natsort();
}
示例6: 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();
}