I want to copy elements of specific indices/keys from one php array to another. I came across this post and tried the following:
$a1=array(10,15,20,25,30);
$indices=array(2,4);
$result=array_intersect_key($a1,array_flip($indices));
print_r($result);
But my result is like this
Array ( [2] => 20 [4] => 30 )
I want the keys in the new array to start from [0]
. ie., I want the result to be
Array ( [0] => 20 [1] => 30 )
I looked at array_combine()
but is there any other efficient way to do this whole process.