I am working with php, and made this little function to only return an array with the same month, but I need this to be returned in order of day too, I tryed to use sort, usort and neither worked out.
$jsonFile = file_get_contents(BASE_TEMPLATE . '/templates/json/' . AMBIENTE . '/' . 'demo_birthday' . '-data.json');
$jsonData = json_decode($jsonFile);
If I print $jsonData I get and array with 25 objects, something like this:
array(25) {
[0]=> object(stdClass)#91 (6) {
["id"]=> string(3) "105"
["day"]=> string(1) "6"
["month"]=> string(7) "febrero"
["name"]=> string(15) "diego fernandez"
["created"]=> string(19) "2021-02-18 07:16:05"
["modified"]=> string(19) "2021-02-18 07:34:18"
}
.
.
.
[24]=> object(stdClass)#115 (6) {
["id"]=> string(3) "129"
["day"]=> string(2) "25"
["month"]=> string(1) "2"
["name"]=> string(15) "martin riquelme"
["created"]=> string(19) "2021-02-18 07:16:06"
["modified"]=> string(19) "2021-02-18 07:16:06"
}
};
// this is used as an array map to compare with actual month
$arrayMonth = array(
array('ENERO', 'ENE', '01', '1'),
array('FEBRERO', 'FEB', '02', '2'),
array('MARZO', 'MAR', '03', '3'),
array('ABRIL', 'ABR', '04', '4'),
array('MAYO', 'MAY', '05', '5'),
array('JUNIO', 'JUN', '06', '6'),
array('JULIO', 'JUL', '07', '7'),
array('AGOSTO', 'AGO', '08', '8'),
array('SEPTIEMBRE', 'SEPT', '09', '9'),
array('OCTUBRE', 'OCT', '10'),
array('NOVIEMBRE', 'NOV', '11'),
array('DICIEMBRE', 'DIC', '12')
);
// this puts the json data on Slides
foreach ($jsonData as &$slide) {
$resultNull = getBirthdayMonth($actualMonth, $slide, $arrayMonth);
if (!empty($resultNull)) {
array_push($result, getBirthdayMonth($actualMonth, $slide, $arrayMonth));
}
}
// This is the function that I need to return in order of day
function getBirthdayMonth($actualMonth, $slide, $arrayMonth)
{
$month = array();
if (in_array(strtoupper($slide->month), $arrayMonth[$actualMonth - 1])) {
array_push($month, array($slide->day, $arrayMonth[$actualMonth - 1][0], $slide->name));
}
return $month;
}
I need that this array, month, get saved in orden of day, I don't seem to understand what I'm doing wrong here.
This is my actual output when I use print_r(getBirthdayMonth($actualMonth, $slide, $arrayMonth));
Array ( [0] => Array ( [0] => 6 [1] => FEBRERO [2] => diego fernandez ) )
Array ( [0] => Array ( [0] => 2 [1] => FEBRERO [2] => mirko valencia ) )
Array ( [0] => Array ( [0] => 5 [1] => FEBRERO [2] => pablo soto ) )
Array ( [0] => Array ( [0] => 1 [1] => FEBRERO [2] => lorena onate ) )
Array ( [0] => Array ( [0] => 5 [1] => FEBRERO [2] => daniela zuñiga ) )
But I need to get this:
Array ( [0] => Array ( [0] => 1 [1] => FEBRERO [2] => lorena onate ) )
Array ( [0] => Array ( [0] => 2 [1] => FEBRERO [2] => mirko valencia ) )
Array ( [0] => Array ( [0] => 5 [1] => FEBRERO [2] => daniela zuñiga ) )
Array ( [0] => Array ( [0] => 5 [1] => FEBRERO [2] => pablo soto ) )
Array ( [0] => Array ( [0] => 6 [1] => FEBRERO [2] => diego fernandez ) )