Tag Archives: keys

Jessica entertaining herself with a set of Keys Jessica | My Life 13 FEB 2012

Of course at this age, just about anything is capable of thoroughly entertaining our young lady, but Jessica in particular has a wonderful fascination with keys.

Which of course means that no set of keys are safe in this house any more! :)

(And yes, she normally claps her hands together when we sing her this song!)

PHP: How to Create a Single String of Array Keys using Implode CodeUnit 09 NOV 2011

PHP’s implode function is extremely useful for flattening a one dimensional array into a string. This time around, we want to create a flat string of an array’s keys, ignoring the actual values for a change.

To achieve this is actually very simple – it’s just a matter of combining the stock standard array_keys() and implode() functions together!

So given an array that looks like this:

$myarray = array('green'=>'leaf','blue'=>'sky','red'=>'apple');

We can get a flattened string reading green||blue||red by doing the following:

echo implode('||',array_keys($myarray));

Simple. The array_keys function first returns an array containing the keys of our aforementioned array, before the implode function flattens it using || as a delimiter.


PHP: Merge Two Arrays but Keep Their Keys Intact CodeUnit 03 SEP 2010

Combining two or more arrays whilst keeping their keys intact in PHP is deceptively simple – though not if you assume you need to use a function like array_merge to achieve this!

As you scroll through the various array functions available to you, you will notice that quite a few seem to drop the array keys after they are done, which is pretty useless if all you want to do is basically add two arrays to one another to form one big keyed array.

So how do you do this then?

Simple really. Just literally add them together!

$resultarr = $array1 + $array2;

And just in case you are wondering what the hell is going on, remember that when applied to arrays, the + acts as a union operator.


Keyless My Life 31 AUG 2007

bunch of keysSo I was off sick yesterday from work (not that it stopped me working from home of course), but seeing as I’m feeling a bit better today (note I said a bit, not a lot) I thought Id better shuffle in and get some stuff done. Even with my working off my laptop yesterday, there was some work which I couldnt do remotely, so I thought that seeing as today is my half day again, I’d better come into work super duper early to get everything done that needs to be done so that I can leave at 12 sharp.

So plans were made, I went to bed (round 12 last night, got home from C and then finished the last couple of levels of Lord of the Rings: Return of the King), woke up at 5, had breakfast, got ready and prepared to leave at 5:30 only to discover that I couldn’t find my office keys! I looked high and low (which is something I don’t have to do very often seeing as I am usually quite organised), but to no avail. The damn keys were nowhere to be found – which didn’t help my super duper early to work plan one bit.

So I was forced to hunker down and waste time playing some games until 6 which is the latest I can leave if travelling into UCT by car if I wish to avoid heavy traffic flow. Eventually I got to work round 6:30, trundled up the stairs, thanked my lucky stars that the boss was already at work (meaning I can get into the office) and dumped all my stuff onto my desk.

The final step of which was to take off my long top and hang it over the backrest of my chair.

And of course, as I turned the top upside down over the chair, what should fall out of one of its pockets but wait for it… my damn keys.