explode separates by the delimiter that you give it, in this case "d"
, so it will bring 2 chains the result [11, 08mo2016y]
to the second result you would have to do another explode with the second element and so on, you can do it by recursion or iteration
function explodeFecha($dato) {
$delimitadores = ['d', 'mo', 'y'];
$arreglo = [];
foreach($delimitadores as $delimiter) {
$explodeDato = explode($delimiter, $dato);
$arreglo[] = $explodeDato[0];
$dato = isset($explodeDato[1])? $explodeDato[1] : NULL;
//si usas php 7 o sueperior puedes usar para simplificar
//$dato = $explodeDato[1] ?? NULL;
}
return $arreglo;
}
print_r(explodeFecha('11d08mo2016y'));
It would also be advisable to validate that the format is the desired one so that errors do not appear