View Full Version : Arrays - making one big array from 4

11-13-2010, 10:34 PM
Hi all

I have 4 arrays:


They each contain 10 items and as their names woudl suggest, contain links, titles descriptions and published dates.

Each of the four arrays contain information relating to the other,


$link[0] is the link for $title[0] which is the title for $description[0] which is the description for $pubDate[0]
$link[1] is the link for $title[1] which is the title for $description[1] which is the description for $pubDate[1]

and so on....

Now, I want to put these into a MySQL table so that each row in the MySQL table contains the correct information for each item

I know that if I only had one array (e.g. $link) i would use

foreach( $link as $item )
/* ... MySQL INSERT command */

BUT, how would I go about dealing with the 4 arrays?

I'm guessing I need to make a huge array of the type:

$each_item = array(0 =>$link[0], $title[0], $description[0], $pubDate[0]);

and then i have one array which i can loop through and insert into the MySQL table

I've looked at the combine_array function - I do not think this is what I require here...

Your comments will be gratefully receievd

Many thanks


Phil Jackson
11-13-2010, 10:40 PM
foreach( $link as $key => $_link ) {
echo $title[$key] . $_link . $description[$key];


for($x=0; $x < count($link); $x++){
echo $title[$x] . $link[$x] . $description[$x];

11-13-2010, 11:08 PM
Phil - THANK YOU very much!

I was getting there slowly, but wouldn't have made it tonight that's for sure!

I used your second version as I understand that more so that the first, but I'll study both!

I also ran your function in your signature - very cool!

Kind regards


Phil Jackson
11-13-2010, 11:22 PM
the first example is as follows


by default, the keys of the array would be 0,1.
[0] => foo, [1] => bar

using foreach() and declairing the key within a variable will give you the same value as using $x in the second example.

no worries anyway, and I like my signature too, had fun writing it!