Example #1
0
 function it_proxies_method_calls_to_wrapped_object(\ArrayObject $obj, WrappedObject $wrappedObject)
 {
     $obj->asort()->shouldBeCalled();
     $wrappedObject->isInstantiated()->willReturn(true);
     $wrappedObject->getInstance()->willReturn($obj);
     $this->call('asort');
 }
 function it_proxies_method_calls_to_wrapped_object(\ArrayObject $obj, WrappedObject $wrappedObject, AccessInspectorInterface $accessInspector)
 {
     $obj->asort()->shouldBeCalled();
     $wrappedObject->isInstantiated()->willReturn(true);
     $wrappedObject->getInstance()->willReturn($obj);
     $accessInspector->isMethodCallable(Argument::type('ArrayObject'), 'asort')->willReturn(true);
     $this->call('asort');
 }
Example #3
0
 /**
  * get an array sorted by value.
  */
 public function getArrayProfilSorted()
 {
     $resArraySorted = new ArrayObject($this->getArrayProfil());
     $resArraySorted->asort();
     return $resArraySorted;
 }
Example #4
0
<?php

$array = array('IMG0.png', 'img12.png', 'img10.png', 'img2.png', 'img1.png', 'IMG3.png');
$arr1 = new ArrayObject($array);
$arr2 = clone $arr1;
$arr1->asort();
echo "Standard sorting\n";
print_r($arr1);
$arr2->natcasesort();
echo "\nNatural order sorting (case-insensitive)\n";
print_r($arr2);
Example #5
0
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $plist->insert("zero#{$i}", -$i);
}
printf("\nnset plist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $top = $slist->first();
}
printf("\ntop slist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $alist->asort();
    $top = key($alist);
}
printf("\ntop alist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $top = $plist->top();
}
printf("\ntop plist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $item = $slist->get($i);
}
printf("\nget slist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
Example #6
0
<?php

// SPL stands for Standard PHP Library
$fruits = ["dollar" => 10, "sterlin" => 5, "euro" => 25];
$obj = new ArrayObject($fruits);
foreach ($obj as $key => $value) {
    echo "{$key} ... {$value}" . PHP_EOL;
}
$obj->asort();
foreach ($obj as $key => $value) {
    echo "{$key} ... {$value}" . PHP_EOL;
}
$obj->ksort();
foreach ($obj as $key => $value) {
    echo "{$key} ... {$value}" . PHP_EOL;
}
/*
Flag Effect

ArrayObject::STD_PROP_LIST  Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.).
ArrayObject::ARRAY_AS_PROPS Entries can be accessed as properties (read and write).
*/
var_dump($obj->dollar);
$obj->setFlags(ArrayObject::ARRAY_AS_PROPS);
var_dump($obj->dollar);
foreach ($obj as $key => $value) {
    echo "{$key} => {$value}" . PHP_EOL;
}
<?php

/* Prototype  : int ArrayObject::asort()
 * Description: proto int ArrayIterator::asort()
 * Sort the entries by values. 
 * Source code: ext/spl/spl_array.c
 * Alias to functions: 
 */
echo "*** Testing ArrayObject::asort() : basic functionality ***\n";
$ao1 = new ArrayObject(array(4, 2, 3));
$ao2 = new ArrayObject(array('a' => 4, 'b' => 2, 'c' => 3));
var_dump($ao1->asort());
var_dump($ao1);
var_dump($ao2->asort('blah'));
var_dump($ao2);
var_dump($ao2->asort(SORT_NUMERIC));
var_dump($ao2);
?>
===DONE===
Example #8
0
<?php

$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
$fruitArrayObject = new ArrayObject($fruits);
$fruitArrayObject->asort();
foreach ($fruitArrayObject as $key => $val) {
    echo "{$key} = {$val}\n";
}
<?php

/* Prototype  : int ArrayObject::asort()
 * Description: proto int ArrayIterator::asort()
 * Sort the entries by values. 
 * Source code: ext/spl/spl_array.c
 * Alias to functions: 
 */
echo "*** Testing ArrayObject::asort() : basic functionality ***\n";
class C
{
    public $prop1 = 'x';
    public $prop2 = 'z';
    private $prop3 = 'a';
    public $prop4 = 'x';
}
$c = new C();
$ao1 = new ArrayObject($c);
var_dump($ao1->asort());
var_dump($ao1, $c);
?>
===DONE===
 public function asort()
 {
     $this->lazyLoadArray();
     parent::asort();
 }
 /**
  * Implementation of ArrayObject::asort().
  *
  * Sorts the entries such that the keys maintain their correlation with the
  * entries they are associated with. This is used mainly when sorting
  * associative arrays where the actual element order is significant.
  *
  * No value is returned.
  */
 public function asort()
 {
     $this->arrayObject->asort();
 }