Skip to content

Instantly share code, notes, and snippets.

View useless-stuff's full-sized avatar
🤓
Learning

1317 useless-stuff

🤓
Learning
View GitHub Profile
@useless-stuff
useless-stuff / php_caching_iterator.php
Created February 16, 2016 13:37
PHP - CachingIterator
<?php
$nav = array(
'Home' => '/home',
'Products' => '/products',
'Company' => '/company',
'Privacy Policy' => '/privacy-policy',
);
/**
* Class NavBuilder
@useless-stuff
useless-stuff / php_limit_iterator.php
Last active February 16, 2016 11:09
PHP - LimitIterator
<?php
/**
* Class RandomObject
*/
class RandomObject
{
protected $value;
/**
@useless-stuff
useless-stuff / php_filter_iterator.php
Created February 16, 2016 09:56
PHP - Filter iterator
<?php
/**
* Class ServerList
*/
class ServersList extends RecursiveArrayIterator
{
}
/**
@useless-stuff
useless-stuff / php_recursive_iterator_iterator.php
Created February 15, 2016 16:10
PHP - Recursive iterator iterator
<?php
$userInput = array(
'user' => array(
'name' => 'Mario',
'surname' => 'Rossi',
'address' => array(
'home' => 'via di qui, 23',
'work' => 'wherever plaza',
)
),
@useless-stuff
useless-stuff / php_recursive_array_iterator.php
Last active February 16, 2016 10:03
PHP - RecursiveArrayIterator
<?php
/**
* Class Message
*/
class Message
{
public $title;
public $body;
public $attachments = array();
@useless-stuff
useless-stuff / php_array_iterator.php
Last active February 12, 2016 14:57
PHP - ArrayIterator
<?php
// Example 1, alphabetic order
$availableServices = ['Building a website', 'SEO', 'SEM', 'Logo design', 'Mobile applications'];
$servicesCollection = new ArrayIterator($availableServices);
$servicesCollection->natsort();
foreach ($servicesCollection as $service) {
print_r((array)$service);
}
/*
@useless-stuff
useless-stuff / php_countable.php
Last active February 12, 2016 11:35
PHP - Countable
<?php
/**
* Class EmployeesCollection
*/
class EmployeesCollection implements Countable
{
protected $employees = array();
/**
@useless-stuff
useless-stuff / php_seekable_iterator.php
Last active February 12, 2016 11:08
PHP - SeekableIterator
<?php
/**
* Class ObjectPicker
*/
class ObjectPicker implements SeekableIterator{
protected $data = array();
protected $position = 0;
/**
@useless-stuff
useless-stuff / php_recursive_iterator.php
Last active August 18, 2023 12:54
PHP - Recursive Iterator
<?php
/**
* Class Skills
*/
class Skills implements RecursiveIterator{
protected $data;
protected $position;
/**
* Skills constructor.
@useless-stuff
useless-stuff / php_iteratoriterator.php
Created February 11, 2016 12:10
PHP - IteratorIterator
<?php
// IteratorIterator is a wrapper to work with others Iterator
/**
* Class ImagesFilter
*/
class ImagesFilter extends IteratorIterator
{
/**
* @param $status