0

I have two variables that contain some data as shown below

$main_headings = [Business Structure,Business Management];

to make comma separated array i use explode

$main_headings = explode [',','Business Structure,Business Management'];

and second variable contain data like this

$sub_headins = [Competitive Positioning, Diversification of Fund Mix, Unit Holding Pattern-Management Quality, Organizational Structure];

same i use explode with second variable to make array

$sub_headins = explode ('-', [Competitive Positioning, Diversification of Fund Mix, Unit Holding Pattern-Management Quality, Organizational Structure];)

After this my second variable convert into two arrays

array1() = [Competitive Positioning, Diversification of Fund Mix, Unit Holding Pattern];

array2() = [Management Quality, Organizational Structure];

now i want my output like this

  • Business Structure

    • Competitive Positioning

    • Diversification of Fund Mix

    • Unit Holding Pattern

  • Business Management

    • Management Quality
    • Organizational Structure

I use for each but i failed to get this output

here is my code

foreach ($main_headings as $main_heading) {
    echo $main_heading;
    echo '<br>';
    foreach ($sub_headings as $sub_heading) {
        echo $sub_heading;
         echo '<br>';
    }
}

output of my code

Business Structure Competitive Positioning, Diversification of Fund Mix, Unit Holding Pattern Management Quality, Organizational Structure Business Management Competitive Positioning, Diversification of Fund Mix, Unit Holding Pattern Management Quality, Organizational Structure

3
  • 1
    what do you retrieve instead of what do you expected? Commented Jun 21, 2017 at 10:15
  • @AlessandroMinoccheri i update my question with my output Commented Jun 21, 2017 at 10:16
  • You first 5 example lines are all syntactically incorrect. That does not help us understand what you have or what you want Commented Jun 21, 2017 at 10:18

2 Answers 2

1
echo "<ul>";
foreach ($main_headings as $main_heading) {
    echo "<li>";
    echo $main_heading;
    echo "<ul>";
        foreach ($sub_headings as $sub_heading) {
            echo "<li>";
            echo $sub_heading;
            echo '</li>';
        }
    echo "</ul>";
    echo "</li>";
}
echo "</ul>";
Sign up to request clarification or add additional context in comments.

Comments

1

try this:

foreach ($main_headings as $main_heading) {
    echo '<p>' . $main_heading . '</p>';
    foreach ($sub_headings as $sub_heading) {
        echo '<p style="text-indent=10px;">' . $sub_heading . '</p>';
    }
}

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.