2
I’ll just put the part where I’m having trouble!
The array that I need, needs to be in this format.
Example 1:
Array
(
[atributos] => Array
(
[atributo] => Array
(
[nome] => Tamanho
[valor] => 35
),
[atributo] => Array
(
[nome] => Cor
[valor] => AZUL/ROSA
)
)
)
But the closest I could come was this! Example 2:
Array
(
[atributos] => Array
(
[atributo] => Array
(
[nome] => Cor
[valor] => AZUL/ROSA
)
)
)
Let’s go to the real problem, whether I have two or more attributes within the array:
$arrayAtributos = array('Tamanho' => 35, 'Cor' => 'AZUL/ROSA');
When reading from the foreach, so you can add the indexes and values next to the node, "attributes/attribute"
$arrayAtributos = array('Tamanho' => 35, 'Cor' => 'AZUL/ROSA');
foreach ($arrayAtributos as $nome => $valor) {
$xmlArray['atributos']['atributo']['nome'] = $nome;
$xmlArray['atributos']['atributo']['valor'] = $valor;
}
print_r($xmlArray);
Only the last index is added to the array, ignoring the rest, as if it were a group by name + value
How is it done, so that all attributes are added within this multidimensional array using the foreach, as in the first example?
Complete XML template and already correctly generated with only one attribute!
But I need to add more attributes like in the example:
<atributos>
<atributo>
<nome>Tamanho</nome>
<valor>35</valor>
</atributo>
<atributo>
<nome>Cor</nome>
<valor>AZUL/ROSA</valor>
</atributo>
</atributos>
And it’s only getting the last attribute of the array
<atributos>
<atributo>
<nome>Cor</nome>
<valor>AZUL/ROSA</valor>
</atributo>
</atributos>
Ball Show is Library @Masnathan, thanks for sharing, fitted like a glove!
– Williams