note 43187 deleted from function.array-merge by levim

From: Date: Mon, 24 Feb 2014 22:52:32 +0000
Subject: note 43187 deleted from function.array-merge by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198673@lists.php.net to get a copy of this message
Note Submitter: niv at NOSPAM iaglans dot DE ---- [Editor's Note: If the keys are truly numeric, array_merge will do the trick. But if they are strings, as the example below, you can use array_merge(array_values($array1), array_values($array2)); since it's more beautiful. -- victor@php.net] i recognized there is no function with that you can add two number-Arrays: Example: <?php // you have two arrays: array1 = array (['0'] =>"blahblupp", ['1'] => "bluppblah" ); array2 = array (['0'] =>"tirili", ['1'] => "tralala" ); // and want following as a result: result = array (['0'] =>"blahblupp", ['1'] => "bluppblah", ['2'] =>"tirili", ['3'] => "tralala" ); // following function does the addition: function array_add($array1, $array2) { $result = $array1; $h = sizeof($array1); for ($i = 0; $i < sizeof($array2); $i++) { $result[$h] = $array2[$i]; $h++; } return $result; } ?> just added because I didn't find a ready-to-use script here.

« previous php.notes (#198673) next »