Note that there are some explanatory texts on larger screens.

plurals
  1. POMultidimensional Array - foreach, within a foreach
    primarykey
    data
    text
    <p>I have a multi dimensional array that is printing out exactly how I want it, however, I have become stuck on figuring out how I can construct it into the for each loop that i'm looking for. </p> <p><strong>Please Note</strong> : $handle is a field the client entered in the backend.</p> <pre><code>&lt;?php $gp = Mage::getStoreConfig('social_code/social_group/google_field'); $ld = Mage::getStoreConfig('social_code/social_group/linkedin_field'); $tw = Mage::getStoreConfig('social_code/social_group/twitter_field'); $fb = Mage::getStoreConfig('social_code/social_group/facebook_field'); $social_array = array( "facebook" =&gt; array( 'class' =&gt; "facebook", 'url' =&gt; 'https://www.facebook.com/', 'handle' =&gt; $fb ), "twitter" =&gt; array( 'class' =&gt; "twitter", 'url' =&gt; 'https://www.twitter.com/', 'handle' =&gt; $tw ), "linked-in" =&gt; array( 'class' =&gt; "linked-in", 'url' =&gt; 'http://www.linkedin.com/company/', 'handle' =&gt; $ld ), "google-plus" =&gt; array( 'class' =&gt; "google-plus", 'url' =&gt; 'https://plus.google.com/', 'handle' =&gt; $gp ) ); ?&gt; </code></pre> <p>Now i wish to spit this out as an unordered list so i have the below, but its still not working for me.</p> <pre><code>&lt;ul&gt; &lt;?php foreach ($social_array as $name =&gt; $group) :?&gt; &lt;?php foreach ($group as $class =&gt; $url) :?&gt; &lt;li&gt;&lt;a href="&lt;?php echo ("$url"); ?&gt;" class="&lt;?php echo ("$class;") ?&gt;"&gt;&lt;?php echo ("$group"); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; </code></pre> <p>I would like it so that it loops through all the social array and prins something similar to this </p> <pre><code>&lt;li&gt;&lt;a href="&lt;?php echo ($url);?&gt;&lt;?php echo ($handle);?&gt;" class="&lt;?php echo ($class); ?&gt;"&gt;&lt;?php echo $name; ?&gt;&lt;/a&gt;&lt;/li&gt; </code></pre> <p>or so understood better</p> <pre><code>&lt;li&gt;&lt;a href="http://www.facebook.com/handle" class="facebook"&gt;Facebook&lt;/a&gt;&lt;/li&gt; </code></pre> <p>Also if I'm making this over complicated for myself please let me know.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload