Filling array with different data, but same range in PHP

Asked

Viewed 155 times

0

I have the following code that is working perfectly, but I need the results within the $arrayDiasSemestre are '1' to the Monday, '2' to the Tuesday and so on...

$inicio = new DateTime($start_date);
$fim = new DateTime($end_date);
$fim->modify('+1 day');

$interval = new DateInterval('P1D');
$periodo = new DatePeriod($inicio, $interval ,$fim);

foreach($periodo as $data){
    $arrayDiasSemestre[] = $data->format("l");
}   

How could I change this entry at the time of filling in the array? Would anyone know any way to do that?

1 answer

2


If I understand your question just use w which is the day of the week (numerical), instead of l which is the name of the day of the week.

foreach($periodo as $data){
    $arrayDiasSemestre[] = $data->format("w");
}

Example: http://ideone.com/wLeRhX

  • 1

    He wants the returns with the days of the week instead of the days of the month? That’s it?

  • 2

    @Erloncharles I think so, instead of the name of the day of the week.

  • 1

    This question would not solve?

  • 1

    @Erloncharles I think this question is the inverse of the one you put on the link. Ie the AP wants a number.

  • 1

    Hummm, ok, now I understand what he needs. He wants the day of the month for a day of the week on a date. Is that it, or does he just want the number that represents the day of the week? Or the number that represents the order of the date in the range?

  • 1

    We’ll know soon enough :)

  • 1

    That’s right, my friends! Barbada, I didn’t know I had 'w' in this role too... Only he uses 0 for Monday and so on and I use 1 for Monday... But I’m going to change in the comic book and leave it like this you’re going to marry right!

  • 1

    @Erloncharles seems to have read it correctly :) I will delete the comments here, if you can/want to delete them too.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.