我有
foreach(["ge","en","ru"] as $lang)
{
Tour_trans::create([
"tour_id" => $tour->id,
"lang_id" => Langs::where('lang', $lang)->first()->id,
"title" => $data["" . $lang . "_title"],
"location" => $data["" . $lang . "_location"],
"dept_time" => $data["" . $lang . "_dept_time"],
"depture_time" => $data["" . $lang . "_dept_time"],
"return_time" => $data["" . $lang . "_return_time"],
"body" => $data["" . $lang . "_body"],
"days" => $data["all_days"]->$lang
]);
}
$ data是一个json对象。一切正常,除了最后一行
"days" => $data["all_days"]->$lang
我收到错误类stdClass的对象无法转换为字符串。 在$ data [“all_days]中有3个数组对象 - ge,en,ru。所以我想在循环中到达这个属性
答案 0 :(得分:0)
这取决于json_decode
的第二个参数的选择:
mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
如果$assoc
设置为true,那么您将返回一个关联数组。如果设置为false,则会得到一个对象。