The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Combining two arrays of different type.
tudsy
post Jan 11 2017, 09:36 AM
Post #1


Advanced Member
****

Group: Members
Posts: 166
Joined: 30-September 14
Member No.: 21,611



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 11 2017, 09:49 AM
Post #2


.
********

Group: WDG Moderators
Posts: 8,074
Joined: 10-August 06
Member No.: 7



Do you mean merge them, or something else?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Jan 11 2017, 10:23 AM
Post #3


Advanced Member
****

Group: Members
Posts: 166
Joined: 30-September 14
Member No.: 21,611



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 11 2017, 02:29 PM
Post #4


.
********

Group: WDG Moderators
Posts: 8,074
Joined: 10-August 06
Member No.: 7



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).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jan 11 2017, 06:09 PM
Post #5


Programming Fanatic
********

Group: Members
Posts: 1,587
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th March 2019 - 01:57 AM