I have one array as
$tmpArr = array('A', 'B', 'C');
I want to process this array and want new array as
$tmpArr[A][B][C] = C
I.e last element becomes the value of final array.
Can anyone suggest the solution? Please help. Thanks in advance
I have one array as
$tmpArr = array('A', 'B', 'C');
I want to process this array and want new array as
$tmpArr[A][B][C] = C
I.e last element becomes the value of final array.
Can anyone suggest the solution? Please help. Thanks in advance
Iterate the array of keys and use a reference for the end of the chain:
$arr = array();
$ref = &$arr;
foreach ($tmpArr as $key) {
$ref[$key] = array();
$ref = &$ref[$key];
}
$ref = $key;
$tmpArr = $arr;
$tmpArr[$tmpArr[0]][$tmpArr[1]][$tmpArr[2]] = $tmpArr[2];
Is that what you want?