Tech

En till Good Old Blogs webbplats

On the uselessness of array_merge_recursive()

I guess that most people have run afoul of the monstrosity that is array_merge_recursive(). In short a merge of array(‘a’=>2, ‘b’=>3) and array(‘b’=>4) gives you array(‘a’=>2,’b’=>array(3,4)) which isn’t the result that one would expect. So, as usual, I’ve created a gist that outlines the problem and gives a more sensible alternative. http://gist.github.com/271920

Läs mer

Ensuring that values are in an array

I’ve run across situations where I want to ensure that some values exist in a non-associative array (without getting duplicates). The way I’ve usually solved it is: if (!in_array(‘nid’, $fields)) { $fields[] = ‘nid’; } if (!in_array(‘title’, $fields)) { $fields[] = ‘title’; } This is kind of ugly, and the more values you want to…

Läs mer

PHP cli script for inverting hex colors

Here’s a gist of the script I used for creating the inverted NeoPro theme in my last post. This way I could do most of the conversion automatically and just tweak some stuff for contrast. http://gist.github.com/190235

Läs mer