jack jack - 1 month ago 9
PHP Question

Pull a specific key data from multidimensional array

I'm trying to pull out the data from multidimensional array, but I get this error each time I'm trying to write the path!. I don't know what's the problem since the path name is correct!.

The error:

Notice: Undefined index: Shp2 in C:\xampp\htdocs\xml\xml.php on line 32


and this's the array

Array
(
[Shp] => Array
(
[test] => Array
(
[Shp2] => Array
(
[customer] => Array
(
[address] => Array
(
[ad1] => new road
[ad2] => newyork
[company] => none
[city] => JO
)

)

)

)

)

)


php code

$arr = $array; //Set this to your converted xml
$comps = $arr['Shp']['test'];

foreach($arr as $comp){
if(is_array($comp))
echo $comp['Shp2']['customer']['address']['ad1'];
}


How to fix this error ?

Answer
 $comps = $arr['Shp']['test'];
 foreach ($comps  as $comp) {
 if (is_array($comp))
 echo $comp['Shp2'] ['customer'] ['address'] ['ad1']; } 
 or use this echo $comp['test'] ['Shp2'] ['customer'] ['address'] ['ad1'];
Comments