Currently I want transform dates stored in mysql (dateime) to FR format, here is my current function :
public static function convert_dates($result){
foreach ($result as $key => $value){
if (count($result) != count($result, COUNT_RECURSIVE)){
foreach ($result[$key] as $key2 => $value2){
if(preg_match('#date#', $key2) && !empty($value2) && $value2!='0000-00-00'){
if (preg_match("#^\d{4}\-\d{2}-\d{2}$#", $value2)) {
$result[$key][$key2] = date("d/m/Y", strtotime($value2));
}elseif (preg_match("#^\d{4}\-\d{2}-\d{2} \d{2}\:\d{2}:\d{2}$#", $value2)) {
$result[$key][$key2] = date("d/m/Y H:i:s", strtotime($value2));
}
}
}
}else{
if(preg_match('#date#', $key) && !empty($value) && $value!='0000-00-00'){
if (preg_match("#^\d{4}\-\d{2}-\d{2}$#", $value)) {
$result[$key] = date("d/m/Y", strtotime($value));
}elseif (preg_match("#^\d{4}\-\d{2}-\d{2} \d{2}\:\d{2}:\d{2}$#", $value)) {
$result[$key] = date("d/m/Y H:i:s", strtotime($value));
}
}
}
}
return $result;
}
I call this function when I fetch array results from query, it can be single item or many items.
Actually it works, but there is any way to improve the code?
Thanks for answers.