Issue
I have this array and a value liken this...
'FirstBranch'
Array => (
['January'],
['February'],
['March']
)
And I need to create another array with the following structure...
['FirstBranch'] => array(
['January'] => array(
'Value',
'%',
'Unit'
),
['February'] => array(
'Value',
'%',
'Unit'
),
['March'] => array(
'Value',
'%',
'Unit'
),
)
I tried to push the values through a foreach, but it doesn't work. The code I did looked like this...
foreach( $months as $month ){
$resultArray['FirstBranch'] = array(
$month => array('Value',
'%',
'Unit'
)
);
}
When i do this, throws an error and it just doesn't work... Any ideas?
Solution
You can append your array using for each loop
<?php
$array = array('January', 'February', 'March');
$array2 = array('Value', '%', 'Unit');
$newarray = array();
foreach ($array as $key) {
$newarray['FirstBranch'][$key] = $array2;
}
print_r($newarray);
Answered By - Muhammad Usman Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.