foreachループ内で2つの配列
Php: foreachループ内の2つの配列 | Code Hero
Code is: tn – and Name: Tunisia
Code is: us – and Name: United States
Code is: fr – and Name: France
【例1】こちらを使用した。
$codes = array(‘tn’, ‘us’, ‘fr’);
$names = array(‘Tunisia’, ‘United States’, ‘France’);
foreach($codes as $key => $value) {
echo “Code is: ” . $codes[$key] . ” – ” . “and Name: ” . $names[$key] . “<br>”;
}
tn
Tunami
us
United States
fr
France
【例2】
$my_array = array(
’tn’ => ‘Tunisia’,
’us’ => ‘United States’,
‘fr’ => ‘France’);
foreach ($my_array as $k => $v) {
echo $k;
echo ‘<br>’;
echo $v;
echo ‘<br>’;}