Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Combining two arrays of different type.

Posted by: tudsy Jan 11 2017, 09:36 AM

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

Posted by: Christian J Jan 11 2017, 09:49 AM

Do you mean merge them, or something else?

Posted by: tudsy Jan 11 2017, 10:23 AM

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.

Posted by: Christian J Jan 11 2017, 02:29 PM

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).

Posted by: CharlesEF Jan 11 2017, 06:09 PM

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)