0

I have edited my question. I am trying to loop through each array and use it inside one foreach loop, is this possible?

foreach ($exhibitor as $exhibitors)
{
    //Foreach loop of each variable we need
    foreach ($exhibitorsLoop as $i) {
        $names[] = $i['exhibitor']['exhname'];
        $logos[] = $i['exhibitor']['onlinelogo'];
        //Sponsorship level 2-11
        $packages[] = $i['exhibitor']['package'];
        $descriptions[] = $i['exhibitor']['description'];
        $websites[] = $i['exhibitor']['website'];
    }
}

How I plan to use it

        <div>
            <img class="img-responsive" src="<?php $logo ?>" alt="">
        </div>
        <div class="col-sm-8">
            <h1 style="margin-top:0;"><?php echo $name; ?></h1>
            <h2><?php echo $website; ?></h2>
        </div>

When I print a value, such as print_r($logos), I get all the values. When I write a foreach loop such as

foreach ($names as $name) {
 echo $name;
}

It also returns the value. But i'm having trouble getting it to return properly in the html block. Do I need to write a foreach loop for each array (names, logos, packages, etc.)?

I have tried a few different array merge methods but nothing gives me the final result I am looking for. I would like to have each exhibitor be looped through and use each key value somewhere in the html.

2 Answers 2

1

Your code fragment makes no sense here:

    //sub loop foreach 
    foreach ($jsonLoop as $i) {

    //example data
    $data= $i['value']['subvalue'];

    }

Because you are resetting $data many times but finally this variable will store only last value. What I think you need instead is just:

    //example data
    $data[] = $jsonLoop;

And instead of your second part:

<?php foreach ($item as $items)
    foreach ($jsonLoop as $i) : ?>

<div class="col-sm-12">
    testing: <?php echo $data ?>
</div>

<?php endforeach; ?>

Just output your data collected:

    print_r($data);

If you need to have formatted html you can extend it but all you need is in your $data now.

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

Comments

0

Here is how I am doing it, I think this works for me: Inside of the second loop I just get everything

    foreach ($exhibitorsLoop as $i) {
      $data[] = $exhibitorsLoop;
    }

And then in the HTML I call specifically what I need from the array

<table>
    <?php foreach ($data as $d) : ?>
      <tr>
        <td> <?php echo $d[0]['exhibitor']['exhname']; ?> </td>
        <td> <?php echo $d[0]['exhibitor']['onlinelogo']; ?> </td>
      </tr>
    <?php endforeach; ?>
</table>

If this isn't the cleanest way let me know but I think this is what I am after.

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.