Twig – The loop Variable

The loop variable

Inside of a for loop block you can access some special variables:

Variable Description
loop.index The current iteration of the loop. (1 indexed)
loop.index0 The current iteration of the loop. (0 indexed)
loop.revindex The number of iterations from the end of the loop (1 indexed)
loop.revindex0 The number of iterations from the end of the loop (0 indexed)
loop.first True if first iteration
loop.last True if last iteration
loop.length The number of items in the sequence
loop.parent The parent context
{% for user in users %}
    {{ loop.index }} - {{ user.username }}
{% endfor %}


The loop.length, loop.revindex, loop.revindex0, and loop.last variables are only available for PHP arrays, or objects that implement the Countable interface. They are also not available when looping with a condition.


Learned today: redis-cli command line options

So, it’s just info you can find with redis-cli –help 🙂 but I didn’t find it in the official documentation.

Usage: redis-cli [OPTIONS] [cmd [arg [arg …]]]

  • -h <hostname> Server hostname (default:
  • -p <port> Server port (default: 6379)
  • -s <socket> Server socket (overrides hostname and port)
  • -a <password> Password to use when connecting to the server
  • -r <repeat> Execute specified command N times
  • -i <interval> When -r is used,  waits <interval> seconds per command. It is possible to specify sub-second times like -i 0.1
  • -n <db> Database number
  • -x Read last argument from STDIN
  • -d <delimiter> Multi-bulk delimiter in for raw formatting (default: \n)
  • –raw Use raw formatting for replies (default when STDOUT is not a tty)
  • –help Output this help and exit
  • –version Output version and exit

cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:

When no command is given, redis-cli starts in interactive mode.
Type “help” in interactive mode for information on available commands.

If PHP Were British

Funny post:

Example 😀


try { // Code here } catch (Exception $e) { // Handle exception die('Message'); }

The try … catch block is an excellent example of PHP’s lack of manners. Far too direct to be allowed in the new PHP. Additionally, the word “die” is so very depressing. This new block, although more verbose, is vastly more polite and upbeat:

would_you_mind { // Code here } actually_i_do_mind (Exception £e) { // Politely move on cheerio('Message'); }

SOLID design


Enough chatter, let’s get to it. SOLID is an acronym. It stands for:

  1. Single Responsibility Principle
  2. Open-Closed Principle
  3. Liskov Substitution Principle
  4. Interface Segregation Principle
  5. Dependency Inversion Principle

Please see article here.