我有一个多维数组,它准确地打印出了我想要的方式,但是,我一直在思考如何将它构造到我所要寻找的for每个循环中。
请注意:$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>我喜欢它,这样它就可以遍历所有的社会数组和prins,类似于这个。
<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>如果我把这件事弄得太复杂了,请告诉我。
发布于 2013-08-28 14:45:10
<ul>
<?php foreach ($social_array as $name => $group) :?>
<li><a href="<?php echo $group['url'].$group['handle']; ?>" class="<?php echo $group['class']; ?>"><?php echo $name; ?></a></li>
<?php endforeach; ?>
</ul>发布于 2013-08-28 14:46:02
如果我理解得对的话,我想这就是你要找的。
<ul>
<?php foreach ($social_array as $name => $group) :?>
<li><a href="<?php echo $group['url'].$group[handle']; ?>" class="<?php echo $group['class']; ?>"><?php echo $name
<?php endforeach; ?>
</ul>发布于 2013-08-28 14:48:45
没有必要进行内部预测。
<?php foreach ($social_array as $name => $group) :?>
<li><a href="<?php echo $group['url'] ?>" class="<?php echo $group['class'] ?>"><?php echo $group['class']; ?></a></li>
<?php endforeach; ?>https://stackoverflow.com/questions/18491031
复制相似问题