Example #1
0
 public function setCollection(Collection $collection)
 {
     $this->_collection = $collection->getCollection();
 }
Example #2
0
 public function getCollection()
 {
     $this->load();
     return parent::getCollection();
 }
            $this->collection[] = $value;
        } else {
            $this->collection[$index] = $value;
        }
    }
    public function offsetUnset($index)
    {
        unset($this->collection[$index]);
    }
}
$numbers = ['a', 'b', 'c', 'd'];
// using collection
echo 'Collection:<br>';
$numbersCollection = new Collection($numbers);
echo 'After initialisation<br>';
var_dump($numbersCollection->getCollection());
echo '<hr>';
$numbersCollection[4] = 'e';
echo 'After setting [4]<br>';
var_dump($numbersCollection->getCollection());
echo '<hr>';
$numbersCollection[] = 'f';
echo 'After setting []<br>';
var_dump($numbersCollection->getCollection());
echo '<hr>';
echo '<br><br><br>';
// using array
echo 'Array:<br>';
echo 'After initialisation<br>';
var_dump($numbers);
echo '<hr>';
Example #4
0
 /**
  * Adds collection to current collection
  *
  * @param Collection $collection
  *
  * @return void
  */
 public function addCollection(Collection $collection)
 {
     $this->initialize(array_merge($this->getCollection(), $collection->getCollection()));
 }
Example #5
0
        echo "offsetSet() called with [{$index}], [{$value}]<br>";
        if (is_null($index)) {
            $this->collection[] = $value;
        } else {
            $this->collection[$index] = $value;
        }
    }
    public function offsetUnset($index)
    {
        unset($this->collection[$index]);
    }
}
echo '<h3>initialise</h3>';
$numbers = ['tahi', 'rua', 'toru', 'wha'];
$numbersCollection = new Collection($numbers);
printf('Collection after initialisation: %s<br>', json_encode($numbersCollection->getCollection()));
echo '<hr>';
echo '<h3>foreach()</h3>';
foreach ($numbersCollection as $number) {
    echo "{$number}<br>";
}
echo '<hr>';
echo '<h3>set</h3>';
$numbersCollection[4] = 'rima';
printf('Collection after setting [4]: %s<br>', json_encode($numbersCollection->getCollection()));
for ($i = 0; $i < count($numbersCollection); $i++) {
    printf('%s<br>', $numbersCollection[$i]);
}
echo '<hr>';
echo '<h3>append</h3>';
$numbersCollection[] = 'ono';