多个阵列爆炸,我希望使用爆炸此类型输出
1,1000,AA 2,2000,BB 3,3000,CC
<?php
$data1= "1,2,3";
$data2= "1000,2000,3000";
$data3= "AA,BB,CC";
$array = explode(',', $data1);
foreach ($array as $data1)
{
echo $data1;
echo $data2;
echo $data3."<br>";
}
?>
多个阵列爆炸 我希望使用爆炸输出
1 1000 AA
2 2000 BB
3 3000 CC
答案 0 :(得分:2)
您需要做的就是将每个原始数据项分解为一个数组,然后使用索引处理一个数组以引用其他两个数组。
<?php
$data1= "1,2,3";
$data2= "1000,2000,3000";
$data3= "AA,BB,CC";
$arr1 = explode(',', $data1);
$arr2 = explode(',', $data2);
$arr3 = explode(',', $data3);
foreach ( $arr1 as $key => $val ) {
echo sprintf( '%s %s %s<br>', $val, $arr2[$key], $arr3[$key] );
}
结果:
1 1000 AA<br>2 2000 BB<br>3 3000 CC<br>
或者如果在浏览器中看到
1 1000 AA
2 2000 BB
3 3000 CC
答案 1 :(得分:0)
使用此代码可以帮助您
如果字符串之间有空格(在AA之后,BB之后),则在爆炸中使用空格(“”),如果有新行,则在爆炸中使用\ n
<?php
$str = "1,1000,AA 2,2000,BB 3,3000,CC";
$arr = explode(" ",$str);
print_r($arr);
$arr1 = array();
$arr2 = array();
$arr3 = array();
foreach($arr as $val){
$value = explode(",",$val);
$arr1[] = $value[0];
$arr2[] = $value[1];
$arr3[] = $value[2];
}
print_r($arr1);
print_r($arr2);
print_r($arr3);
?>
答案 2 :(得分:-1)
$data1= "1,2,3";
$data2= "10,20,30";
$data3= "100,200,300";
$arr1 = explode(',', $data1);
$arr2 = explode(',', $data2);
$arr3 = explode(',', $data3);
foreach ( $arr1 as $key => $val ) {
echo $val;
echo $arr2[$key];
echo $arr3[$key];
}