I have the following array and by using array_push & I am getting not the right result.
Array:
Array
(
[0] => 1039
[1] => 417
[2] => 418
)
Array Push:
array_push($array, array("a","b","c"));
Result:
Array
(
[0] => 1039
[1] => 417
[2] => 418
[3] => Array
(
[0] => a
[1] => b
[2] => c
)
)
I want the a,b,c append to value 417 for example .
Disirable result:
Array
(
[1039] => 1039
[417] => Array
(
[0] => a
[1] => b
[2] => c
)
[418] => 418
)
How can this be done?
SOLUTION:
$data = Array (
0 => 1039,
1 => 417,
2 => 418,
);
foreach( $data as $key => $val ) {
$new_data[$val] = 0;
}
foreach( $new_data as $k => $v ){
if( $k == 417 ){
$new_data[$k] = array( 'p' => 50, 'pp' => 75 );
}
}
print_r($new_data);
use loop to display new array data