0

I am stuck in Laravel, Need expert's help to resolve the issue.

I have multidimentional array, i am developing the api. I have tried to unset it but somehow it throws the error. I have tried to go with array_filter as well, but not possible for me to resolve the issue.

$data =
    Array
(
    [dno] => LUCYELEC
    [mcu] => 007801714078
    [type] => analytic
    [start] => 191018120000
    [end] => 191020115900
    [events] => Array
        (
        )

)
Array
(
    [dno] => LUCYELEC
    [mcu] => 106214191003
    [type] => analytic
    [start] => 191018120000
    [end] => 191020115900
    [events] => Array
        (
            [0] => Array
                (
                    [feebbb] => Array
                        (
                            [0] => Array
                                (
                                    [date-time] => 191018080000
                                    [sub-type] => PQ
                                    [comments] => sdfas
                                    [parameter-list] => sdfasd
                                    [state] => bad
                                    [value] => 9200
                                )

                        )

                )

        )

)

There are some [events] are blank, no array. SO i want to remove it and get the only array oject which has data. I need to create this in Loop like forench or for loop.

Response formate in json

return response()->json(['data'=>$data)]);
vdr
  • 101
  • 1
  • 1
  • 7
  • where are the codes? – Kevin Jun 10 '20 at 07:35
  • HI Kevin, It is attached with the post only. There is array. – vdr Jun 10 '20 at 07:40
  • You are expected to show some effort of solving the problem yourself before asking a question here. Also please refer to [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) – apokryfos Jun 10 '20 at 08:34

1 Answers1

0

You can apply next foreach loop:

foreach($data as $ind=>$record){
     if(empty($record['events'])) unset($data[$ind]);
}

sort($data); // <-- makes indexes begin from 0
Aksen P
  • 4,564
  • 3
  • 14
  • 27