Help - Search - Members - Calendar
Full Version: Combining two arrays of different type.
HTMLHelp Forums > Programming > Server-side Scripting
tudsy
Hi

Just a little problem. How do I combine an array of filenames with an array of numbers?

That is,


$filenames =array("file1", .........);
$numbers = array("23",..............);


Any help will be appreciated.

Thanks. biggrin.gif
Christian J
Do you mean merge them, or something else?
tudsy
QUOTE(Christian J @ Jan 12 2017, 12:19 AM) *

Do you mean merge them, or something else?


Hi

Thanks for that.

Merge them to produce

$result = array("file1", "23", etc........);


Thanks.
Christian J
An array may contain values of different types, so array_merge() should work.

Both your arrays use string values though, since "23" is a string too (unlike 23 without quotes).
CharlesEF
If you want the array in the exact order as your sample, then I think you need to write your own function. array_merge() will work if you don't mind appending the 2nd array to the end of the 1st array.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.