【发布时间】:2020-10-03 12:04:53
【问题描述】:
我有一个数组。然后我使用 php unset 方法从数组中只删除一个索引。然后我将新数组存储在 laravel 会话中。
$GetCartItems = json_decode($request->SessionValue);
unset($GetCartItems->items[$request->ArrIndex]);
$request->session()->put('cart', $GetCartItems);
之后,我使用以下代码从 laravel 会话中重试了数组。现在它是 stdClass 类型的对象,而不是数组。但是,我想要一个数组。
$GetCartItems = Session::get('cart');
这是我想从 laravel 会话中得到的。
App\Cart {#282 ▼
+items: array:3 [▼
0 => array:6 [▼
"item_id" => "29"
"qty" => array:1 [▶]
"price" => "1235"
"size" => array:1 [▶]
"item" => App\Product {#283 ▶}
"produ" => array:1 [▶]
]
1 => array:6 [▶]
2 => array:6 [▶]
]
+totalQty: 3
+totalPrice: 3705
+count: 3
+ArrCount: 3
}
这是我在删除一个带有元素的索引并存储在 laravel 会话中之后得到的。
{#282 ▼
+"items": array:3 [▼
0 => {#283 ▼
+"item_id": "29"
+"qty": array:1 [▶]
+"price": "1235"
+"size": array:1 [▶]
+"item": {#284 ▶}
+"produ": array:1 [▶]
}
1 => {#286 ▶}
2 => {#290 ▶}
]
+"totalQty": 6
+"totalPrice": 7410
+"count": 6
+"ArrCount": 3
}
我怎样才能摆脱这个 stdClass 类型的对象并得到我想要的??
【问题讨论】:
-
我想你已经序列化了 App\Cart 模型和嵌套的 items 关系?我说的对吗?