亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法在 Laravel 中使用 Illuminate\\Http\\JsonResponse

無法在 Laravel 中使用 Illuminate\\Http\\JsonResponse

PHP
慕容森 2023-07-01 09:38:10
我有這樣的數據集:$data[] =Array(    [u_d] => ABCDEF    [0] => Array        (        [one] => oned        [two] => 222        [three] => three        [four] => 444        [five] => 555        [events] => Array            (                [0] => Array                    (                        [feed] => Array                            (                                [0] => Array                                    (                                        [date-time] => 191018080000                                        [sub-type] => abc                                        [comments] => test comments                                        [parameter-list] => para1, para2                                        [state] => bad                                        [value] => 1000                                    )                            )                    )            )        )    [1] => Array        (            [one] => two            [two] => 224562            [three] => thyyree            [four] => 445344            [five] => 5345355            [events] => Array                (                )        ))我只需要獲取事件并刪除空事件。然而,首先我嘗試獲取像這樣的事件,但它給出了一個錯誤。                               $new = [];                                 for($i=0 ; $i < count($data)-1 ; $i++)                                {                                  if(count($data[$i]['events']) > 0)                                  {                                                                        $new[] = $data[$i]['events'];                                                                     }                                                                  }                                print_r ($new);但它給了我一個錯誤: Cannot use object of type Illuminate\Http\JsonResponse as array誰能幫我解決這個問題嗎?
查看完整描述

2 回答

?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

你需要解碼$data[0]而不是$data因為你正在做

$data[] =

同樣的 for 循環,你應該這樣做

if(count($data[0][$i]['events']) > 0)


查看完整回答
反對 回復 2023-07-01
?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

您可以像這樣使用 Laravelcollect() 方法:

collect($your_array)->toJson();

https://laravel.com/docs/7.x/collections


查看完整回答
反對 回復 2023-07-01
  • 2 回答
  • 0 關注
  • 361 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號