Reputation: 21
I have to access to all values stored in a big multidimensional array, here's an example of print_r the array:
Array
(
[Novedad] => Array
(
[@attributes] => Array
(
[CUNENov] => 4545454545
)
)
[Periodo] => Array
(
[@attributes] => Array
(
[FechaIngreso] => 1998-12-12
[FechaRetiro] => 2021-11-12
[FechaLiquidacionInicio] => 2021-05-01
[FechaLiquidacionFin] => 2021-05-30
[TiempoLaborado] => 10829
[FechaGen] => 2021-05-05
)
)
[Devengados] => Array
(
[Basico] => Array
(
[@attributes] => Array
(
[DiasTrabajados] => 30
[SueldoTrabajado] => 1258955.00
)
)
)
)
The thing I want to do is extract the values from that array, I have tried this way:
<?php
$cunenov = $array['Novedad']['@attributes']['CUNENov'];
but doesn't work.. Any suggests?. Thanks in advance.
Upvotes: 0
Views: 44
Reputation: 7515
I wanted you to see the "constructed" array and the outputs .. Stand alone, this php
works .. Paste it into a stand alone php
file and determine what you're doing differently to not achieve the same result.
Building out the array, and then print_r
so you can validate it's the same structure as your array.
<?php
$test = Array();
$test['Novedad'] = array();
$test['Novedad']['@attributes'] = array();
$test['Novedad']['@attributes']['CUNENov'] = 4545454545;
print_r( $test );
Yields:
Array
(
[Novedad] => Array
(
[@attributes] => Array
(
[CUNENov] => 4545454545
)
)
)
Then we echo:
$cunenov = $test['Novedad']['@attributes']['CUNENov'];
echo "Value is $cunenov";
Yields
Value is 4545454545
Upvotes: 1