Ranjith Ranjith - 5 months ago 22
PHP Question

Get elements from Multidimensional array

i have an array with this structure

$font = Array
(
["family"] => ABeeZee
["category"] => sans-serif
["variants"] => Array
(
[0] => regular
[1] => italic
)

["subsets"] => Array
(
[0] => latin
)

)


i want to get the elements like $family = ABeeZee
,$variants = regular, italic

Answer

Please have a look attached snippet.

Check it over here. https://eval.in/600521

<?php
$arr=array(
"family" => 'ABeeZee',
"category" => "sans-serif",
"variants" => array("regular","italic"),
"subsets" => array("latin"));
foreach($arr as $key=>$arr){
    if(is_array($arr)){
        echo "$".$key ."=". implode(",",$arr);
    }else{
        echo "$".$key ."=". $arr;
    }
    echo "<br>";
}
?>

Above snippet will return following output.

$family=ABeeZee
$category=sans-serif
$variants=regular,italic
$subsets=latin