/** * Detects and sets "concatenated flag" type arguments. * @param string $argument The argument string. * @return boolean */ private function detectConcatFlag($argument) { if (substr($argument, 0, 1) === '-') { for ($i = 1; isset($argument[$i]); $i++) { $this->flags->push($argument[$i]); } return true; } return false; }
public function testGetItemCountFromCollectionm() { $collection = new Collection([]); $collection->push([1 => 'First', 2 => 'Second']); $this->assertEquals(2, $collection->count()); }
<?php require_once '../lib/collection.inc.php'; use Ballen\Collection\Collection; $eol = '<br>'; $fruits = new Collection(['strawberry' => 'Red', 'orange' => 'Orange', 'lemon' => 'Yellow', 'grape' => 'Purple']); echo 'Total fruits in our collection:' . $fruits->count() . $eol; // We'll add Apples to our collection... $fruits->push(['apple' => 'Green']); echo 'We added an Apple to our collection so now we have: ' . $fruits->count() . ' fruits.' . $eol; // We'll not iterate over our fruits and output the data... $fruits->each(function ($key, $value) use($eol) { echo 'An ' . $key . ' is ' . $value . $eol; }); echo "The first fruit is: " . $fruits->first(); echo "The last fruit is: " . $fruits->last(); // We can reset our fruit collection (to either a new list or emtpy it entirely) $fruits->reset(); echo 'Now that we\'ve reset the collection we now have ' . $fruits->count() . ' items!';
<?php require_once '../lib/collection.inc.php'; use Ballen\Collection\Collection; $cars = new Collection(); // Add some cars... $cars->push('Ford Focus'); $cars->push('BMW 580i'); $cars->push('Toyota Avensis'); $cars->push('Marcos Martina Spyder'); // Lets output the cars as a JSON object echo $cars->all()->toJson(); // How many cars do we have? echo '<p>Total cars:' . $cars->count() . '</p>'; // Add some more cars... $cars->push(['Ferrari Modena', 'Seat Leon', 'Peugeot 307', 'Toyota Auris']); // How many do we have now? echo '<p>Total cars after adding four:' . $cars->count() . '</p>'; // Lets get the first car in our collection... echo '<p>First car added was: ' . $cars->first() . '</p>'; // Get the last car from our collection... echo '<p>Last car added was: ' . $cars->last() . '</p>'; $mini_cooper = 'Nope!'; if ($cars->has('Mini Cooper')) { $mini_cooper = 'Yes!'; } echo '<p>Do we have a Mini Cooper in our collection? ' . $mini_cooper . '</p>'; // Lets shuffle (randomise) our collection... $cars->shuffle(); echo '<p>Randomised our order now looks like: ' . $cars->all()->toJson() . '</p>'; // We now have zero items in our collection...