How to Flatten and Merge Arrays in PHP
There is no built in function for taking a multi dimensional array in PHP and flattening it into a single array. However, it's pretty easy to accomplish in a one liner. Here is the code
How to Cast an Array to an Object with PHP
It's short and sweet.
$obj_from_array = (object)['key'=>'val'];
How to Get a Random Item from an Array in PHP
Use this snippet for grabbing a random item from an array in php
$fruits = ['apple', 'banana', 'carrot', 'date', 'elderberry'];
// => 'banana'
PHP's `array_flip` makes the keys the values and the valu...
How Beautiful is Ruby?
Working with Ruby and in particular Rails, it's easy to take the beauty inherent in the language for granted. I mean look at this code. If you read it aloud to yourself, it reads like an english sentence that any non programmer can understand.
Descending Sort By in Model For Active Record Hash on Created_at attribute
If you have a couple collections from the database and you want to sort it without the help of Active Record, take a look at the sort_by method on Array type. I've used this before when I have a couple of collections which are slightly different but I nee...