You probably want to use MultipleIterator
:
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_ASSOC);
$mi->attachIterator(new ArrayIterator($valor), 'val');
$mi->attachIterator(new ArrayIterator($valor2), 'val2');
foreach ($mi as $values) {
extract($values);
echo '<tr><td>', $val, '</td><td>', $val2, '<br></td></tr>';
}
It iterates over both arrays at the same time and for each iteration yields $values
as an array like this:
array('val' => 1, 'val2' => 4);
In this example 1
and 4
would come from $valor
and $valor2
respectively. I then use extract()
inside the loop to bind those keys to actual variables.