php - Add item in array with key? -


i have php code , tried many times no luck. case have 1 array declare in difference place , want merge in looping

$data[] = ['sales' => 'mark'];  for($i=0;$i<3;$i++){  data[$i]="some value".$i; } 

the result

array ( [0] => array ( [sales] => mark ) [0] => value0 [1] => value1 [2] => value2 ) 

my expected

array ( [0] => array ( [sales] => mark [0] => value0 [1] => value1 [2] => value2 ) ) 

i think looking for:

$data['sales'] = 'mark';  for($i=0;$i<3;$i++){  $data[$i]="some value".$i; } $x[0] = $data; print_r($x);  print_r($data); 

that outputs this:

array (     [0] => array         (             [sales] => mark             [0] => value0             [1] => value1             [2] => value2         ) ) 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -