Modify array keys in PHP

I'm interested in functional programming lately and was happy to discover that modifying array keys in PHP can be done avoiding any kind of loops. 😃

$greetings = ['hey' => 1, 'ho' => 2];

$greetings = array_combine(array_map(function ($greeting) {
    return strtoupper($greeting);
}, array_keys($greetings)), array_values($greetings));

// ['HEY' => 1, 'HO' => 2]
Did you like this post?
Previous post

Vue.js adopts a one-way data flow model, which means that state always flows from the parent components to the child components and is usually passed via props. This is a great way of managing state, because it makes things predictable. Ultimately, state needs to be shared between components. This post will explore ways in which parent and child components can share state and most importantly how child components can pass state back to their parents.

Next post
I was looking for a way to handle single click and double click events on the same element in Vue.js. While it looked like 'v-on:dblclick' is going to cover this requirement nicely I soon discovered it’s not ideal. While double clicking 'click' event fires too (as soon as the first click is registered), which makes it hard to handle both types of events separately from each other.