Extract values ​​from a multidimensional array

I get an array from the following code

$classes = $mb->makeNumericArray($data['GetClassesResult']['Classes']['Class']);
$result = $classes;

    echo '<pre>';
        print_r($result);
    echo '</pre>';

and array

Array
(
    [0] => Array
        (
            [ClassScheduleID] => 
            [ClassDescription] => Array
                (
                    [Description] => 
                    [Program] => Array
                        (
                            [ScheduleType] => DropIn
                        )
                )

            [Staff] => Array
                (
                    [SortOrder] => 
                }
        )   

     [1] => Array
        (
            [ClassScheduleID] => 
            [ClassDescription] => Array
                (
                    [Description] => 
                    [Program] => Array
                        (
                            [ScheduleType] => DropIn
                        )
                )

            [Staff] => Array
                (
                    [SortOrder] => 
                }
        )   
)   

I tried to extract the code with reference to this qaru.site/questions/1579064 / ... ,

foreach($result as $res)
    {
        $classscheduleid= $res['ClassScheduleID'];
        echo $classscheduleid;

    } 

I have currently tried this code to print ClassScheduleID.

But it does not retrieve data correctly. It skips the values ​​in [0], and in the rest of the array, it repeats the result.

Can someone tell me how I can get ClassScheduleIDalong with Description, ScheduleTypeand sortorderfrom a full array?

+4
source share
2 answers

You need to iterate over the internal array:

foreach($classes as $key => $internal_array){
    $classscheduleid= $internal_array['ClassScheduleID'];
    echo $classscheduleid;
    //again, ClassDescription is also array
    foreach($internal_array['ClassDescription'] as $internal_key => $res){

       echo " $internal_key => $res";//etc

    }
} 

Or is it recursive:

function echo_array($a, $key){
    foreach($a as $key1 => $array1){
        if(!is_array($array1)){
            echo "$key $key1 : $array1<br/>";
        }else{
            echo_array($array1,$key1);
        }
    }
}
echo_array($a,'');
0

foreach ($result as $row) $result [0], $result [1]... $result[0]["ClassScheduleID"], , print_r ($result), emptry, .

0

All Articles