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:
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.