user3514052
user3514052

Reputation: 429

how to combine two different arrays to associative array?

I have two arrays

1. Array ( [0] => Array ( [0] => 151 ) [1] => Array ( [0] => 152 ) [2] => Array ( [0] => 148 ) ) 

2. Array ( [0] => 2019-03-11 [1] => 2019-03-08 [2] => 2019-03-09 )

How can I get Array like this

array(
    151 => 2019-03-11,
    152 => 2019-03-08,
    148 => 2019-03-09
)

Upvotes: 0

Views: 19

Answers (2)

AbraCadaver
AbraCadaver

Reputation: 78994

Extract the sub array elements from $array1 and use them as the keys and $array2 values as the values:

$result = array_combine(array_column($array1, 0), $array2);

Upvotes: 1

user3514052
user3514052

Reputation: 429

Sorry, right after I asked a question, I was able to solve it this way.

$a= call_user_func_array('array_merge', $a);

$c = array_combine($a, $b);

Upvotes: 0

Related Questions