Esempio n. 1
0
 public function testNullParamsToConstructor()
 {
     $animals = new PrettyArray(null, null);
     $this->assertEquals(array(), $animals->to_a());
 }
Esempio n. 2
0
 /**
  * Methods: getSet, getSet_
  *
  * Will get a 'set' from PrettyArray. Calling it destructively will force the return value to be references to the current PrettyArray.
  *
  * <code>
  * $arr = new PrettyArray(array(1,2,3,4,5));
  * $o = $arr->getSet(1, 2)->to_a();
  * print_r($o);
  * </code>
  * <pre>
  * Array
  * (
  *     [1] => 2
  *     [2] => 3
  * )
  * </pre>
  *
  * @link http://ruby-doc.org/core-1.9.3/Array.html#method-i-slice
  * @param mixed $start
  * @param int $length
  * @return PrettyArray
  */
 public function getSet_($start, $length)
 {
     $ret = new PrettyArray();
     $count = 0;
     foreach ($this->data as $key => &$value) {
         if ($start == $key || $count > 0) {
             $ret->setByReference($key, $value);
             $count++;
             if ($count == $length) {
                 break;
             }
         }
     }
     return $ret;
 }