0

Let's say I have the following array:

Array
(
    [Particulier] => Array
        (
            [Weekend] => Array
                (
                    [2015] => Array
                        (
                            [01] => Array
                                (
                                )

                            [02] => Array
                                (
                                )

                            [03] => Array
                                (
                                )

                            [04] => Array
                                (
                                    [startDate] => 24-04-2015
                                    [endDate] => 27-04-2015
                                )

                            [05] => Array
                                (
                                    [startDate] => 01-05-2015
                                    [endDate] => 04-05-2015
                                )

                            [06] => Array
                                (
                                )

Is it possible for me to completely remove all empty arrays (including keys), like so:

Array
(
    [Particulier] => Array
        (
            [Weekend] => Array
                (
                    [2015] => Array
                        (
                            [04] => Array
                                (
                                    [startDate] => 24-04-2015
                                    [endDate] => 27-04-2015
                                )

                            [05] => Array
                                (
                                    [startDate] => 01-05-2015
                                    [endDate] => 04-05-2015
                                )

If any other information is required, please ask. I'm new to this. Thanks in advance!

  • 2
    use unset() to remove array. – Bushra Shahid Apr 21 '15 at 08:28
  • This question probably is a duplicate, but not of the one @Rizier123 linked to, since that applies to a one-dimensional array. Unfortunately, some of the mods on this site don't read the questions before closing them, but try not to be too discouraged. http://stackoverflow.com/a/6528748/2136840 should help. – ChicagoRedSox Apr 21 '15 at 08:46
  • @ChicagoRedSox OP maybe has a multidimensional array, but it still works with `array_filter()` to get the results what OP wants. So he just has to filter the right dimension. – Rizier123 Apr 21 '15 at 08:48
  • @Rizier123 Sorry if I sounded inflammatory, but I feel like this site has a habit of biting new users and turning them away. Anyway, it's possible I'm misreading the question, but I believe the OP is asking to remove elements from an indeterminate level of an array, which would require recursion. – ChicagoRedSox Apr 21 '15 at 09:04
  • @ChicagoRedSox Thanks for your response:). Will try it! –  Apr 21 '15 at 10:01

0 Answers0