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
Post a Comment