tmartin314
tmartin314

Reputation: 4171

Merge two associative arrays

I have two arrays:

aid = [$aid]=>1
amount = [$aid] = $70

How can I rewrite these two separate arrays to be one array:

payout = [aid] => $aid, [amount] => $70

Upvotes: 1

Views: 5361

Answers (4)

karim79
karim79

Reputation: 342625

If you want the resulting structure to resemble this:

Array
(
    [aid] => 234323
    [amount] => 32454
)

Then you can simply use the + operator to combine the two arrays:

$payout = $aid + $amount;

Demo: http://www.ideone.com/ZxP97

Upvotes: 2

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

for($i = 0; $i < count($aid); $i++){
    $payout[$i]["aid"] = $aid[$i];
    $payout[$i]["price"] = $price[$i];
}

Upvotes: 0

sethvargo
sethvargo

Reputation: 26997

I believe you are looking for php's array_merge(...)

http://php.net/manual/en/function.array-merge.php

Upvotes: 8

rajmohan
rajmohan

Reputation: 1618

You can use array_merge(). Check this link http://www.w3schools.com/php/func_array_merge.asp

Upvotes: 2

Related Questions