2

I have a multi dimensional array with the structure:

  • Name
  • Address
  • Area
    • Area Type 1
    • Area Type 2
    • Area Type 2

I have a loop that grabs the Name and Address for each business and echos them out. Now what I want to be able to do is now grab the area and chuck that out for each business. My loop thus far is as follows:

foreach ($data AS $key => $value) {
    echo '<ul>';
        echo '<li>';
            echo $value['Name'];
        echo '</li>';
        echo '<li>';
            echo $value['Address'];
        echo '</li>';
    echo '<li>';
                    foreach ($data as $row) {
                        echo $data['Area'];
                    }
        echo '</li>';
        echo '</ul>';
}

I can output all the Areas in one go with:

    foreach($data as $row)
        {
           foreach($row['Area'] as $areaout)
              {
                 echo $areaout;
               }
         }

But I need it to echo out with it's respective name and address

1 Answer 1

1

Shouldn't you simply replace

foreach ($foo as $row) {
   echo $foo['Area'];
}

by

echo '<ul>';
foreach ($value['Area'] as $v) {
   echo '<li>' . $v . '</li>';
}
echo '</ul>'

?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.