我一直坚持这个问题很长一段时间了。在laravel的社交名媛的帮助下,我有了这个特殊的阵列。
//to use in Object-C
__block NSInteger pre = 0;
__block NSInteger next = 0;
[WrapClass getResult:10 callback:^(NSInteger preValue, NSInteger nextValue) {
pre = preValue;
next = nextValue;
}];
我想要做的是从"first_name" => "xxx"
"last_name" => "xx"
"email" => "xxx@gmail.com"
"work" => array:2 [▼
0 => array:4 [▼
"employer" => array:2 [▼
"id" => "xxxxxxxxxxxxxx"
"name" => "FBI"
]
"location" => array:2 [▶]
"start_date" => "0000-00"
"id" => "496298904045521"
]
1 => array:6 [▶]
]
获取first_name
,last_name
,email
和name
,然后将其保存在数据库中。问题是我似乎无法检索工作的名称,而是给我这个错误信息
(1/1)ErrorException 未定义的索引:雇主
我该如何使这项工作?在这里很丢失。
控制器
work
}
答案 0 :(得分:2)
您正以错误的方式访问雇主姓名。你跳过一些索引:
$w = collect([$work=>[$usersocialite->user['work'][0]['employer']=>[$usersocialite->user['work'][0]['employer']['name']]]]);
我无法理解你在做什么。但我想你想要这样的东西:
$w = collect(['work'=>[$work[0]['employer']=>[$work][0]['employer']['name']]]]);
答案 1 :(得分:0)
要访问多维数组中的工作名称,您可以使用以下内容:
$user->work = $usersocialite->user['work'][0]['employer']['name'];
或者您可以使用Laravel辅助函数array_get
:
$user->work = array_get($usersocialite->user, 'work.0.employer.name');
上面的代码将替换代码:
$work=$usersocialite->user['work'];
$w = collect([$work=>[$usersocialite->user['employer']=>[$usersocialite->user['name']]]]);
$flattened = $w->flatten();
$flatten->all();
$user->work = $usersocialite->user[$flatten];