我有一个名为$formAnswers
的数组和一个名为$defaultData
的对象数组。
我需要从[Id]
获取$formAnswers
并在$defaultData
中找到以获取特定内容块。然后检查内容块中[InputKeyName]
的{{1}},并将$formAnswers
从[Value]
推送到$formAnswers
。
$defaultData
中可以多次[Id]
次。$formAnswers
中$defaultData
只会出现一次。直到[Id]
循环,一切都按预期工作,但从那里它不起作用。我该如何解决这个问题?
这是我的功能:
for
以下是public function pushFormAnswersToDefaultData(array $defaultData, array $formAnswers)
{
foreach ($defaultData["info"] as $defaultDataContent)
{
foreach ($defaultDataContent as $defaultDataProfile)
{
if (is_array($defaultDataProfile))
{
foreach ($defaultDataProfile as $defaultKey => $defaultDataProfileContent)
{
//Content Block
for($c=0;$c<count($formAnswers);$c++)
{
if($defaultDataProfileContent->Id == $formAnswers[$c]['Id'])
{
foreach ($defaultDataProfile[$defaultKey] as $nameKey => $profileDataContentInside)
{
if ($nameKey == $formAnswers[$c]['InputKeyName'])
{
$defaultDataProfileContent->$formAnswers[$c]['InputKeyName'] = $formAnswers[$c]['Value'];
}
}
}
}
}
}
}
}
return $defaultData;
}
:
$formAnswers
以下是 $formAnswers = Array (
[0] => Array
(
[Id] => 0142643741
[InputKeyName] => FromDate
[Value] => 28.03.2017
)
[1] => Array
(
[Id] => 5338820142
[InputKeyName] => Menu
[Value] => Green Salad
)
[2] => Array
(
[Id] => 7351265992
[InputKeyName] => Area
[Value] => Mc Cully Green
)
[3] => Array
(
[Id] => 02643029354
[InputKeyName] => Menu
[Value] => Fried Rice
)
[4] => Array
(
[Id] => 9808392996
[InputKeyName] => Description
[Value] => Bolognese is super easy and a true classic Italian pasta
)
[5] => Array
(
[Id] => 02643029354
[InputKeyName] => FromDate
[Value] => 04.01.2017
)
)
:
$defaultData