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)]);
3
  • where are the codes? Commented Jun 10, 2020 at 7:35
  • HI Kevin, It is attached with the post only. There is array. Commented Jun 10, 2020 at 7: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? Commented Jun 10, 2020 at 8:34

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, Thank you for your reply, I check this but seens it unset all the records. All array goes blank.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.