第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

在緩存數(shù)據(jù)中搜索給出數(shù)組第一個索引 1

在緩存數(shù)據(jù)中搜索給出數(shù)組第一個索引 1

PHP
寶慕林4294392 2021-09-05 16:58:14
$this->getCachedCategories();//Above code Stores the data in cache for future use. So, it goes to the database only //one time and next time pick the data from cache. So far everything is good.//I have a search criteria which is in the form of array. I filter above cache data based //upon the search criteria and gets the data.foreach ($userInputsForFilter as $key => $value) {    $this->Categories = $this->Categories->where($key, $value);}這是屏幕截圖。如果您注意到檢索到的數(shù)據(jù)的第一個索引是 1 而不是 0。實際上第二個記錄是在過濾緩存數(shù)據(jù)后出現(xiàn)的。你能告訴為什么在搜索緩存數(shù)據(jù)時會發(fā)生這種情況嗎?轉(zhuǎn)到數(shù)據(jù)庫時不會發(fā)生這種情況。數(shù)組到 JSON 代碼$CategoryResponse = $this->iCategory->All([], []);return \Response::json($CategoryResponse, 200);
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經(jīng)驗 獲得超8個贊

Laravel 的Collections, 和 PHP 中的數(shù)組通常可以是關(guān)聯(lián)的,這意味著第一個索引可以是不一定為 0 的東西。當(dāng)通過Response::json(), or轉(zhuǎn)換為 JSON 時return response->json(),它可以被視為objectJS 中的數(shù)組而不是數(shù)組。為了解決這個問題,將 轉(zhuǎn)換Collection為一個數(shù)組,并indexed通過 PHP 的array_values()函數(shù)更改為一個:


$CategoryResponse = $this->iCategory->All([], []);

return response()->json(array_values($CategoryResponse->toArray()), 200);

// Older Laravel syntax

// return \Response::json(array_values($CategoryResponse->toArray()), 200);

在 JSON 響應(yīng)中,它應(yīng)該正確顯示為具有0第一個索引的數(shù)組。


查看完整回答
反對 回復(fù) 2021-09-05
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號