Reputation: 5418
I have this two arrays
$views[] = $id;
$pid[] = $page_id;
which prints
Array
(
[0] => 9
[1] => 12
[2] => 13
[3] => 14
[4] => 15
)
Array
(
[0] => 174
[1] => 221
[2] => 174
[3] => 174
[4] => 174
)
now i want to create new array from this result like(first will be the key and second be the value)
Array
(
[9] => 174
[12] => 221
[13] => 174
[14] => 174
[15] => 174
)
I have tired array_push function but didnt work for me.
Upvotes: 1
Views: 145
Reputation: 3608
You can use array_combine:
Creates an array by using one array for keys and another for its values
ie:
$newarr = array_combine($array1, $array2); //$array1: key, $array2: value
Upvotes: 2
Reputation: 25950
$result = array();
for($i=0; $i<sizeof($array1); $i++)
$result[$array1[$i]] = $array2[i];
Upvotes: 2