循环数组php(foreach)
大家好,我有个问题,我有一个250值的数组,我想这样输出所有这些值循环数组php(foreach),php,Php,大家好,我有个问题,我有一个250值的数组,我想这样输出所有这些值 foreach($myArray as $x => $x_value) { $pic = strtolower($x); // here i want to echo only 83 value like this // <td>83 value</td> <td>83 value</td> <td>83 value</td
foreach($myArray as $x => $x_value) {
$pic = strtolower($x);
// here i want to echo only 83 value like this
// <td>83 value</td> <td>83 value</td> <td>83 value</td>
echo "<img src='http://<my website>/$pic.png'/>$x_value";
echo "<br>";
}
foreach($x=>x$u值的myArray){
$pic=strtolower($x);
//这里我只想重复这样的83个值
//83值83值83值
echo“/$pic.png”/>$x_值”;
回声“
”;
}
伙计们,这是我的阵列
$countries = array
(
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
// 250 country
);
// 83 country in each colmun
// i want to echo <td> 83 country here </td> and <td> 83 country here </td> and <td> 83 country here </td>
$countries=数组
(
“AF”=>“阿富汗”,
“AX”=>“阿兰群岛”,
“AL”=>“阿尔巴尼亚”,
//250个国家
);
//每个科尔曼有83个国家
//我想回应83个国家这里83个国家这里83个国家这里83个国家
我对我的英语很抱歉,我正在尽我最大的努力让你轻松地解开我想要的东西。foreach($x=>myArray$x\u value){
foreach($myArray as $x => $x_value) {
$pic = strtolower($x);
// here i want to echo only 83 value like this
// <td>83 value</td> <td>83 value</td> <td>83 value</td>
if($x==83)
echo "<td>$x</td> <td>$x_value</td>";
echo "<img src='http://<my website>/$pic.png'/>$x_value";
echo "<br>";
$pic=strtolower($x);
//这里我只想重复这样的83个值
//83值83值83值
如果($x==83)
回显“$x$x_值”;
echo“/$pic.png”/>$x_值”;
回声“
”;
}如果不这样使用for()循环,您可以创建自己的计数器
// Array for counting total and 83
$count = array(
"count" => 0,
"countNew" => 0
);
echo "<td>"; //Start with opening a <td>
foreach($myArray as $x => $x_value) {
$count["count"]++; // Keep counting till end of array
$count["countNew"]++; // Count for 250 / 3
$pic = strtolower($x);
// Get interval arraylengt / 3
$tdThis = intval(floor(count($myArray) / 3));
echo $x_value;
if($count["countNew"] >= $tdThis){
// Whenever we reach the 83 reset to 0 for new count to 83
$count["countNew"] = 0;
// Close </td> on every 83 countries
echo "</td>";
// If we don't reach the array end add new td
if($count["count"] === count($myArray)){
echo "<td>";
}
}
}
//用于计算总数和83的数组
$count=数组(
“计数”=>0,
“countNew”=>0
);
回声“//从打开一个窗口开始
foreach($x=>x$u值的myArray){
$count[“count”]+;//继续计数直到数组结束
$count[“countNew”]+;//计数为250/3
$pic=strtolower($x);
//获取间隔排列长度t/3
$tdThis=intval(楼层(计数($myArray)/3));
echo$x_值;
如果($count[“countNew”]>=$tdThis){
//每当我们到达83时,将新计数重置为83
$count[“countNew”]=0;
//接近每83个国家
回声“;
//如果我们没有到达阵列端,请添加新的td
如果($count[“count”]==count($myArray)){
回声“;
}
}
}
到底是什么问题?我想这样输出这些值:83值83值83值显示$myArray
的某些部分以识别预期内容是的,换句话说250/3您的情况下83
数字是什么?它不是数组键,也不是value@SaSuki,如果我理解,您想启动
回显83
土地值并关闭
,然后重新打开
,依此类推?我