我有一个多维数组,可以准确地打印出我想要的样子,但是,我一直在弄清楚如何将它构建到我正在寻找的 for each 循环中。
请注意:$handle 是客户端在后端输入的字段。
<?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" => array(
'class' => "facebook",
'url' => 'https://www.facebook.com/',
'handle' => $fb
),
"twitter" => array(
'class' => "twitter",
'url' => 'https://www.twitter.com/',
'handle' => $tw
),
"linked-in" => array(
'class' => "linked-in",
'url' => 'http://www.linkedin.com/company/',
'handle' => $ld
),
"google-plus" => array(
'class' => "google-plus",
'url' => 'https://plus.google.com/',
'handle' => $gp
)
);
?>
现在我希望将其作为无序列表吐出,所以我有以下内容,但它仍然不适合我。
<ul>
<?php foreach ($social_array as $name => $group) :?>
<?php foreach ($group as $class => $url) :?>
<li><a href="<?php echo ("$url"); ?>" class="<?php echo ("$class;") ?>"><?php echo ("$group"); ?></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
我想要它,以便它遍历所有社交数组并打印与此类似的东西
<li><a href="<?php echo ($url);?><?php echo ($handle);?>" class="<?php echo ($class); ?>"><?php echo $name; ?></a></li>
或者更好理解
<li><a href="http://www.facebook.com/handle" class="facebook">Facebook</a></li>
另外,如果我让自己变得复杂,请告诉我。