Welcome Guest, Not a member yet? Register   Sign In
Quick question - merging two or more arrays without reindexing
#11

[eluser]xwero[/eluser]
You are right, i guess there is no function to merge arrays preserving the keys.

from the comments on php.net
Quote:
Code:
<?php

$a=array('a'=>'a1','b.'=>'a2','a3','a4','a5');
$b=array(100=>'b1','b2','a'=>'b3','b4');

$a+=$b;

print_r($a);

?>

output:

[a] => a1
[b.] => a2
[0] => a3
[1] => a4
[2] => a5
[100] => b1
[101] => b2
[102] => b4
using the += operator doesn't causes errors when two keys are the same but the value for the first key is saved instead of overwritten by the second value of the same key.


Messages In This Thread
Quick question - merging two or more arrays without reindexing - by El Forum - 06-02-2009, 07:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB