2017-08-28 184 views
0

我有一個會話變量,其中包含各種json對象,我希望能夠更新這些對象。Laravel 5.4更新數組中的值

例如,

$userIndex = 123; 
session()->get('app.users')[$userIndex]['phones']['landline']; 
session()->get('app.users')[$userIndex]['phones']['mobile']; 

如何更新內容的價值?我如何會話put一個新的手機號碼?

session()->get('app.users')[$userIndex]['phones']['mobile'] = '12345678'; 
+0

'會話() - >替換( 'app.users')[$ userIndex] [ '電話'] [ '移動'] = '12345678';' – Gunaseelan

回答

1

如果您需要爲laravel放置新會話變量,使用「put」很重要。你需要用「put」來改變「get」。

例如:

session()->put('app.users')[$userIndex]['phones']['mobile'] = 'YOUR MOBILE NUMBER'; 
+0

這確實不行 – TheRealPapa