Mahesh Gupta
Mahesh Gupta

Reputation: 1892

php associative array multidimensions

I have more than 3d associative array and i want access them frequently but it just not working so please give a solution of this question :

error received: generating array to string conversion

#<!-- BEGAIN SINGLE TESTIMONIAL SLIDE1 -->
$satisfied = array(
    "team-1.jpg" => array(
        "Alin Brown" => array(
            'CEO' => "Message of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
        )
    ),
    "team-2.jpg" => array(
        "Jon Smith" => array(
            'CEO' => "Message of Lorem Ipsum available, but the majority have suffered alteration in some form."
        )
    ),
    "team-4.jpg" => array(
        "Jon Doe" => array(
            'Manager' => "Message of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
        )
    )
);

foreach ($satisfied as $sat => $val) {
    echo"<li>";
    echo"<div class='media testi_media'>";
    echo"<a class='media-left testi_img' href='#'>
    <img src='img/$sat' alt='img'/></a>";
    foreach ($val as $val1 => $val2) {
        echo "<div class='media-body'>
        <h4 class='media-heading'>$val1</h4>";
        echo "<span>$val2</span>";                      
        echo "</div>";
        echo "</div>";
        foreach ($val2 as $val3) {
            echo"<div class='testi_content'>";
            echo"<p>$val3</p>";
            echo"</div>";}
        }
        echo"</li>";
    }
}

Upvotes: 1

Views: 65

Answers (1)

Yogesh
Yogesh

Reputation: 424

<?php#<!-- BEGAIN SINGLE TESTIMONIAL SLIDE1 -->
$satisfied = array(
    "team-1.jpg" => array(
        "Alin Brown" => array(
            'CEO' => "Message of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
        )
    ),
    "team-2.jpg" => array(
        "Jon Smith" => array(
            'CEO' => "Message of Lorem Ipsum available, but the majority have suffered alteration in some form."
        )
    ),
    "team-4.jpg" => array(
        "Jon Doe" => array(
            'Manager' => "Message of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
        )
    )
);

foreach ($satisfied as $sat => $val) {
    echo"<li>";
    echo"<div class='media testi_media'>";
    echo"<a class='media-left testi_img' href='#'>
    <img src='img/$sat' alt='img'/></a>";
    foreach ($val as $val1 => $val2) {
        $designation=array_keys($val2);
        echo "<div class='media-body'>
        <h4 class='media-heading'>$val1</h4>";
         echo "<span>".isset($designation[0])?$designation[0]:""."</span>";//Edited                      
        echo "</div>";
        echo "</div>";
        foreach ($val2 as $designation=>$val3) {
            echo"<div class='testi_content'>";
            echo "<span>$designation</span>";//REmove this if you don't want
            echo"<p>$val3</p>";
            echo"</div>";}
        }
        echo"</li>";
    }

Upvotes: 1

Related Questions