嗨我有以下数组
array(4) {
[0]=>
array(3) {
["id_acreditado"]=>
string(3) "174"
["cantidad"]=>
string(7) "4008.00"
["acreditado"]=>
string(27) "Olga Olivia Lucio Hernandez"
}
[1]=>
array(3) {
["id_acreditado"]=>
string(3) "175"
["cantidad"]=>
string(7) "4008.00"
["acreditado"]=>
string(23) "Enrique Carranco Vences"
}
[2]=>
array(3) {
["id_acreditado"]=>
string(3) "176"
["cantidad"]=>
string(7) "4008.00"
["acreditado"]=>
string(32) "Juana Patricia Contreras Paredes"
}
[3]=>
array(3) {
["id_acreditado"]=>
string(3) "177"
["cantidad"]=>
string(7) "4008.00"
["acreditado"]=>
string(17) "Noemi Cruz Campos"
}
}
我想用上述数组的一些值和不同的索引创建一个二维数组。我正在使用 foreach 循环来实现这一点。
$j=1;
foreach($acreditados as $acreditado){
$tmp['oneCol'] = $j;
$tmp['twoCol'] = $acreditado['acreditado'];
$tmp['threeCol'] = $acreditado['cantidad'];
$info['fourCol'] =$acreditado['id_acreditado'];
$info[]=$tmp;
$j++;
}
$tmp 是一个辅助一维数组,最近添加为双维 $info 数组的一行,但是我没有得到预期的输出。我想要以下内容作为输出:
array(4) {
[0]=>
array(3) {
["oneCol"]=>
int(1)
["twoCol"]=>
string(27) "Olga Olivia Lucio Hernandez"
["threeCol"]=>
string(7) "4008.00"
["fourCol"]=>
string(3) "174"
}
[1]=>
array(3) {
["oneCol"]=>
int(2)
["twoCol"]=>
string(23) "Enrique Carranco Vences"
["threeCol"]=>
string(7) "4008.00"
["fourCol"]=>
string(3) "175"
}
[2]=>
array(3) {
["oneCol"]=>
int(3)
["twoCol"]=>
string(32) "Juana Patricia Contreras Paredes"
["threeCol"]=>
string(7) "4008.00"
["fourCol"]=>
string(3) "176"
}
[3]=>
array(3) {
["oneCol"]=>
int(4)
["twoCol"]=>
string(17) "Noemi Cruz Campos"
["threeCol"]=>
string(7) "4008.00"
["fourcol"]=>
string(3) "177"
}
}