Fill an array with a given value through the function array_fill()
and combine two or more arrays by function array_merge()
<?php
$array1 = [];
//Define um elemento vazio para posterior preenchimento
$vazio = [
"idhis" => null,
"id_user_cartao" => null,
"ponto" => null,
"id_user" => null,
"qtde_pontos" => null,
"iduserpromo" => null
];
//Simula um preenchimento de 30 itens de $array1
foreach(range(1,30) as $n){
$array1[] = [
"idhis" => -$n,
"id_user_cartao" => $n,
"ponto" => $n * 10,
"id_user" => $n * 100,
"qtde_pontos" => $n * 1000,
"iduserpromo" => $n * 10000
];
}
//Cria um array 20 elementos definidos como sendo vazios
$array2 = array_fill(0, 20, $vazio);
//Junta $array1 e $array2
$resultado = array_merge($array1 , $array2);
print_r($resultado);
Test code running on https://repl.it/repls/RemarkableWatchfulDemand
Array
(
[0] => Array
(
[idhis] => -1
[id_user_cartao] => 1
[ponto] => 10
[id_user] => 100
[qtde_pontos] => 1000
[iduserpromo] => 10000
)
[1] => Array
(
[idhis] => -2
[id_user_cartao] => 2
[ponto] => 20
[id_user] => 200
[qtde_pontos] => 2000
[iduserpromo] => 20000
)
[2] => Array
(
[idhis] => -3
[id_user_cartao] => 3
[ponto] => 30
[id_user] => 300
[qtde_pontos] => 3000
[iduserpromo] => 30000
)
[3] => Array
(
[idhis] => -4
[id_user_cartao] => 4
[ponto] => 40
[id_user] => 400
[qtde_pontos] => 4000
[iduserpromo] => 40000
)
[4] => Array
(
[idhis] => -5
[id_user_cartao] => 5
[ponto] => 50
[id_user] => 500
[qtde_pontos] => 5000
[iduserpromo] => 50000
)
[5] => Array
(
[idhis] => -6
[id_user_cartao] => 6
[ponto] => 60
[id_user] => 600
[qtde_pontos] => 6000
[iduserpromo] => 60000
)
[6] => Array
(
[idhis] => -7
[id_user_cartao] => 7
[ponto] => 70
[id_user] => 700
[qtde_pontos] => 7000
[iduserpromo] => 70000
)
[7] => Array
(
[idhis] => -8
[id_user_cartao] => 8
[ponto] => 80
[id_user] => 800
[qtde_pontos] => 8000
[iduserpromo] => 80000
)
[8] => Array
(
[idhis] => -9
[id_user_cartao] => 9
[ponto] => 90
[id_user] => 900
[qtde_pontos] => 9000
[iduserpromo] => 90000
)
[9] => Array
(
[idhis] => -10
[id_user_cartao] => 10
[ponto] => 100
[id_user] => 1000
[qtde_pontos] => 10000
[iduserpromo] => 100000
)
[10] => Array
(
[idhis] => -11
[id_user_cartao] => 11
[ponto] => 110
[id_user] => 1100
[qtde_pontos] => 11000
[iduserpromo] => 110000
)
[11] => Array
(
[idhis] => -12
[id_user_cartao] => 12
[ponto] => 120
[id_user] => 1200
[qtde_pontos] => 12000
[iduserpromo] => 120000
)
[12] => Array
(
[idhis] => -13
[id_user_cartao] => 13
[ponto] => 130
[id_user] => 1300
[qtde_pontos] => 13000
[iduserpromo] => 130000
)
[13] => Array
(
[idhis] => -14
[id_user_cartao] => 14
[ponto] => 140
[id_user] => 1400
[qtde_pontos] => 14000
[iduserpromo] => 140000
)
[14] => Array
(
[idhis] => -15
[id_user_cartao] => 15
[ponto] => 150
[id_user] => 1500
[qtde_pontos] => 15000
[iduserpromo] => 150000
)
[15] => Array
(
[idhis] => -16
[id_user_cartao] => 16
[ponto] => 160
[id_user] => 1600
[qtde_pontos] => 16000
[iduserpromo] => 160000
)
[16] => Array
(
[idhis] => -17
[id_user_cartao] => 17
[ponto] => 170
[id_user] => 1700
[qtde_pontos] => 17000
[iduserpromo] => 170000
)
[17] => Array
(
[idhis] => -18
[id_user_cartao] => 18
[ponto] => 180
[id_user] => 1800
[qtde_pontos] => 18000
[iduserpromo] => 180000
)
[18] => Array
(
[idhis] => -19
[id_user_cartao] => 19
[ponto] => 190
[id_user] => 1900
[qtde_pontos] => 19000
[iduserpromo] => 190000
)
[19] => Array
(
[idhis] => -20
[id_user_cartao] => 20
[ponto] => 200
[id_user] => 2000
[qtde_pontos] => 20000
[iduserpromo] => 200000
)
[20] => Array
(
[idhis] => -21
[id_user_cartao] => 21
[ponto] => 210
[id_user] => 2100
[qtde_pontos] => 21000
[iduserpromo] => 210000
)
[21] => Array
(
[idhis] => -22
[id_user_cartao] => 22
[ponto] => 220
[id_user] => 2200
[qtde_pontos] => 22000
[iduserpromo] => 220000
)
[22] => Array
(
[idhis] => -23
[id_user_cartao] => 23
[ponto] => 230
[id_user] => 2300
[qtde_pontos] => 23000
[iduserpromo] => 230000
)
[23] => Array
(
[idhis] => -24
[id_user_cartao] => 24
[ponto] => 240
[id_user] => 2400
[qtde_pontos] => 24000
[iduserpromo] => 240000
)
[24] => Array
(
[idhis] => -25
[id_user_cartao] => 25
[ponto] => 250
[id_user] => 2500
[qtde_pontos] => 25000
[iduserpromo] => 250000
)
[25] => Array
(
[idhis] => -26
[id_user_cartao] => 26
[ponto] => 260
[id_user] => 2600
[qtde_pontos] => 26000
[iduserpromo] => 260000
)
[26] => Array
(
[idhis] => -27
[id_user_cartao] => 27
[ponto] => 270
[id_user] => 2700
[qtde_pontos] => 27000
[iduserpromo] => 270000
)
[27] => Array
(
[idhis] => -28
[id_user_cartao] => 28
[ponto] => 280
[id_user] => 2800
[qtde_pontos] => 28000
[iduserpromo] => 280000
)
[28] => Array
(
[idhis] => -29
[id_user_cartao] => 29
[ponto] => 290
[id_user] => 2900
[qtde_pontos] => 29000
[iduserpromo] => 290000
)
[29] => Array
(
[idhis] => -30
[id_user_cartao] => 30
[ponto] => 300
[id_user] => 3000
[qtde_pontos] => 30000
[iduserpromo] => 300000
)
[30] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[31] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[32] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[33] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[34] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[35] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[36] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[37] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[38] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[39] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[40] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[41] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[42] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[43] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[44] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[45] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[46] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[47] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[48] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
[49] => Array
(
[idhis] =>
[id_user_cartao] =>
[ponto] =>
[id_user] =>
[qtde_pontos] =>
[iduserpromo] =>
)
)
Why this line of PDO doesn’t look like this: $rowx = $stmtx->fetchAll(); since several copies of bd will come, fetchAll is more indicated
– Marcos Vinicius
thus it would not be necessary to call the function Extract since the result would already come like $emp_itemx= array([0] =>array( "idhis" => "xxxx", "id_user_card" => "xxxx", "dot" => "xxxx", "id_user" => "xxxx", "qtde_points" => "xxxx", "iduserpromo" => "xxxx") );
– Marcos Vinicius
Marcos, thanks for the tip, but my problem is as I described above, the question of the database data I’m not having problems. I really need to complete the blank data in the array!!
– Lucas Dolci
the array you represented is wrong, it is easier to iterate over the return using a foreach at the end rather than while
– Marcos Vinicius
back Array ( [0] => Array ( [idhis] => 'xxx', [id_user_card] => 'xxx', [dot] => 'xxx', [id_user] => 'xxx', [qtde_points] => 'xxx', [idupromoser] => 'xxx'
#; )
– Marcos Vinicius
All right, but how could I complete the result I need?
– Lucas Dolci