PHP code example of fiv / collection
1. Go to this page and download the library: Download fiv/collection library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fiv / collection example snippets
class UserModel {
public function getName(){
}
}
class UsersCollection extend ObjectCollection {
public function objectsClassName(){
return 'UserModel';
}
}
# ....
$users = new UserCollection();
foreach($users as $user){
# at this point you can drop out all you validations
# ObjectCollection guarantee that all items are UserModel
$user->getName();
}
$users->append(123); // Fail. 123 is not instance of UserModel
php
$collection = new \Fiv\Collection\BaseCollection();
$collection[] = 1;
$collection[] = 2;
echo $skeleton->getFirst()