What 20 Lines (or less) of code did you find really useful?
- by Ygam
You can share your code or other's code. Here's a snippet from an array function in Kohana:
public static function rotate($source_array, $keep_keys = TRUE)
{
$new_array = array();
foreach ($source_array as $key => $value)
{
$value = ($keep_keys === TRUE) ? $value : array_values($value);
foreach ($value as $k => $v)
{
$new_array[$k][$key] = $v;
}
}
return $new_array;
}
It was helpful when I was uploading multiple images using multiple file upload forms. It turned this array
array('images' => array(
'name' => array(
0 => 'img1',
1 => 'img0',
2 =>'img2'
),
'error' => array(
0 => '',
1 => '',
2 => ''
into :
array('images' => array(
0 => array(
'name' => 'img1'
'error' => ''
),//rest goes here
How about you? What 20 or less lines of code did you find useful?