so after head i came up with below function which served my purpose :
$mainarray = [
0 => [
0 =>[
0 => [
0 => 'one' ,
1 => 'two' ,
2 => 'three' ,
3 => 'four'
],
1 => [
0 => 'one' ,
1 => 'two' ,
2 => 'three' ,
3 => 'four'
]
]
]
]
Then this array below has the values as the index of the $mainarray
above of what i want to get lets say one
as above ,
$arraywithseacrhindex = [
0 => 0 ,
1 => 0 ,
2 => 0 ,
3 => 0 ,
]
Solution :
$array = $mainarray ;
$arr = $arraywithseacrhindex ;
$counter= count($arr)-1 ;
$result = array() ;
for($i=0; $i< $counter; $i++) {
if(empty( $result ) )
{
// first loop to put $result at per with $array
$result[$arr[$i]] = $array[$arr[$i]] ;
}else{
// this is the trick of the solution
$cResult = current($result);
unset($result);
$result = array() ;
$result[$arr[$i]] = $cResult[$arr[$i]] ;
}
}
var_dump($result);
Hope it helps someone in future .
test2[test[0]][test[1]][test[2]][test[3]]
not work?