Skip to content

Instantly share code, notes, and snippets.

@jbdelhommeau
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbdelhommeau/e4abb53ce78ca0c4467e to your computer and use it in GitHub Desktop.
Save jbdelhommeau/e4abb53ce78ca0c4467e to your computer and use it in GitHub Desktop.
Test
private function getFieldDataValue(NoticeDataLang $fieldData)
{
if ($fieldData->getField()->getType() !== Field::TYPE_SET) {
return [$fieldData->getField()->__toForm() => $fieldData->getValue(false)];
}
if ($fieldData->getChildren()) {
$childData = [];
foreach ($fieldData->getChildren()->toArray() as $child) {
array_push($childData, [$child->getPart() => $this->getFieldDataValue($child)]);
}
return $childData;
}
return [];
}
private function getFieldDataValue(NoticeDataLang $fieldData)
{
if ($fieldData->getField()->getType() !== Field::TYPE_SET) {
return [$fieldData->getField()->__toForm() => $fieldData->getValue(false)];
}
if ($fieldData->getChildren()) {
$childData = [];
foreach ($fieldData->getChildren()->toArray() as $child) {
if (isset($childData[$child->getPart()])) {
$childData[$child->getPart()] = array_merge(
$childData[$child->getPart()],
$this->getFieldDataValue($child)
);
} else {
$childData[$child->getPart()] = $this->getFieldDataValue($child);
}
}
return $childData;
}
return [];
}
$iterate_1 = array(1 => array('key11' => 'value11'));
$iterate_2 = array(1 => array('key12' => 'value12'));
$iterate_3 = array(2 => array('key21' => 'value21'));
$iterate_4 = array(2 => array('key22' => 'value22'));
J'ai ses valeurs à chaque tour de boucle et je dois la "fusionner" à chaque élément précédent.
Le résultat doit-être:
$result = array(
1 => array(
'key11' => 'value11',
'key12' => 'value12',
),
2 => array(
'key21' => 'value21',
'key22' => 'value22',
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment