Hello Fellow Trongate users,
I have an array of public holidays created from a php function as follows:
This works great as it is used by some other functions to do some date calculations,
however, I am passing in $start_date and $end_date as variables to this function and I want to filter the array (or a copy of it) to be returned with only the dates between the start and end date variables in the array.
Any guidance will be appreciated, as I now must acknowledge that I genuinely suck at arrays in php.
Cheers!
Array filtering question
4 years ago
4 years ago
#1
4 years ago
#2
Question unclear to me. Little more code or description will be helpful.
But see if this what you want.
then,
But see if this what you want.
then,
4 years ago
#3
Nice Freiza, but I'm db man and would have done this from SQL instead of pulling your hair out with arrays...
Assuming your data is something like this, KeepCalm:
Result
Assuming your data is something like this, KeepCalm:
Result
4 years ago
#4
Thank you both Frezia and DaFa for responding.
I agree with DaFa, database manipulation would be easier, however, in this case, the array is being generated by a php function I created to get the holidays.
That being said, Frezia's solution was nearer to what was needed in this instance.
I said nearer because there was one error- 'push_array' should actually be 'array_push'.
Thanks Frezia.
Cheers!
I agree with DaFa, database manipulation would be easier, however, in this case, the array is being generated by a php function I created to get the holidays.
That being said, Frezia's solution was nearer to what was needed in this instance.
I said nearer because there was one error- 'push_array' should actually be 'array_push'.
Thanks Frezia.
Cheers!
4 years ago
#5
@Simon, Keepcalm specifically asked for php array, so I gave that answer. But yes I also have to agree manipulating database is so much easier.
@Keepcalm, Thank you very much. And yes it should be array_push, I wasn't using any IDE. And my brain is what it is :)
But I guess you understand the core idea. Let's have fun and enjoy this framework together.
@Keepcalm, Thank you very much. And yes it should be array_push, I wasn't using any IDE. And my brain is what it is :)
But I guess you understand the core idea. Let's have fun and enjoy this framework together.