1

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.

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

2
$result = array();

for($i=0; $i<sizeof($array1); $i++)
    $result[$array1[$i]] = $array2[i];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.