使用array_chunk我已将一组名称拆分为4个名称的组,我想取其中一个组并以4个div显示,div以其中一个成员组名称命名,示例group-&gt; jhon ,mark,giovanni,clara then divs <div id="jhon></div>
<div id="mark"></div>
等等..
我想只在div中显示不等于divs名称的其他名称
答案 0 :(得分:0)
您在输出名称的同时创建DIV?也许这样的事情会有所帮助:
$garray = array("Jhon","Mark","Josh","Buckwheat");
doGroupDiv("Jhon",$garray);
function doGroupDiv($group, $grouparray) {
echo '<div id="' . $group . '">';
foreach ($grouparray as $name) {
if ($name != $group) echo $name . "<BR>";
}
echo '</div>';
}
应该产生:<div id="Jhon">Mark<BR>Josh<BR>Buckwheat<BR></div>
答案 1 :(得分:0)
听起来你正在寻找这样的东西:
<?php
$namesList = array(
"Mark",
"John",
"Giovanni",
"Clara"
);
foreach ($namesList as $name) {
echo "<div id='" . strtolower($name) . "'>\n";
echo "\t<ul>\n";
foreach ($namesList as $innerName) {
if ($innerName != $name) {
echo "\t\t<li>" . $innerName . "</li>\n";
}
}
echo "\t</ul>\n";
echo "</div>\n";
}
?>
哪会产生这个:
<div id='mark'>
<ul>
<li>John</li>
<li>Giovanni</li>
<li>Clara</li>
</ul>
</div>
<div id='john'>
<ul>
<li>Mark</li>
<li>Giovanni</li>
<li>Clara</li>
</ul>
</div>
<div id='giovanni'>
<ul>
<li>Mark</li>
<li>John</li>
<li>Clara</li>
</ul>
</div>
<div id='clara'>
<ul>
<li>Mark</li>
<li>John</li>
<li>Giovanni</li>
</ul>
</div>
答案 2 :(得分:0)
我无法准确地告诉你代码是什么,因为我从未使用过数组块,但它会像下面这样:
foreach($array as $name) {
echo "<div id='$name'><ul>";
foreach($array as $name2) {
if($name2 != $name) {
echo "<li>".$name2."</li>;
}
}
echo "</ul></div>";
}
希望这是您正在寻找的答案。