I am new to php. I am trying to get key and value of each element in special array. I want to save/push them into another array start from zero index. Of course (foreach loop) is the best tool here. Please help me BY YOUR CODE. I know describing this problem is a bit hard, so I have some drawings for you.
$info = array(
<--key--> <--value-->
[10] => 'apple',
[8] => 'orange',
[2] => 'banana',
[23] => 'peach',
)
now I want to have an array like this:
$myGoal = array(
<-key-> <--------value--------->
[0] => array('10'=>'apple'),
[1] => array('8'=>'orange'),
[2] => array('2'=>'banana'),
[3] => array('23'=>'peach')
)
I guess the code I need should be something like below:
$info = array(
[10] => 'apple',
[8] => 'orange',
[2] => 'banana',
[23] => 'peach',
)
$index = 0;
$myGoal = array();
foreach($info as $amount => $friut){
$myGoal[$index] = [$amount][$friut];
$index++;
}
I'll be thank of anybody can help me.