2016-04-16 7 views
-1

こんにちはみんなは、私は疑問を持っていてください、私はこの私の配列を出力し、このループアレイPHP(foreachの)

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>"; 
} 

みんなのようにすべてのこれらの値が欲しい250値を持つ配列を持つ

$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> 

私は自分の英語を残念に思っています。私は自分が望むものを見落とすのをやりやすくするために最善を尽くそうとしています。

+0

正確にはどのような問題がありますか? – DevDonkey

+0

私は出力にこのように、これらの値とします​​83値​​83値 – SaSuki

+0

が、他の言葉で正確に意図されたコンテンツ – RomanPerekhrest

答えて

0
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>"; 

}

1

あなたはこのようなのために()ループを使用しない場合は、独自のカウンタを作ることができます。

// 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>"; 
     } 
    } 
} 
+0

私の最初の投稿を確認してください – SaSuki

+1

@SaSuki、もし私がそれを理解していれば、 '​​'を再起動するよりも '833'土地の値をエコーアウトして ''私 –