Page 1 of 1

multiple arrays in a foreach statement

Posted: Sat Aug 04, 2007 1:29 pm
by lehula
I want to echo the array $tables[1] and array $tables[2]. I have && signs to show what I'm trying to do.
This obviously doesn't work, but how can I get it to work?


preg_match_all('/(<table id="friendtable(..).{150,180}font-size:.?.?.?.?pt">)<a/', $text, $tables);
foreach($tables[1] as $whole && $tables[2] as $number)
{

echo $whole;
echo $number;
}

Posted: Sat Aug 04, 2007 2:47 pm
by volka
From where and how do you get the array $table?

Posted: Sun Aug 05, 2007 8:23 am
by superdezign
You could run through them separately and then merge them.

Code: Select all

$tmp = array();
$index = 0;

foreach($table[1] as $value)
{
    $tmp[$index++] = $value;
}

$index = 0;

foreach($table[2] as $value)
{
    $tmp[$index++] = array($tmp[$index], $value);
}
And then echo them together via the $tmp array. I'm not sure if the increment in the second loop should happen on the left or right side of the assignment... You should take a look into it.