lehula Posted August 4, 2007 Share Posted August 4, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/63337-multiple-arrays-in-a-foreach-statement/ Share on other sites More sharing options...
wintallo Posted August 4, 2007 Share Posted August 4, 2007 My first guess would be to nest two foreach statements, like this: foreach($tables[1] as $whole) { foreach (f$tables[2] as $number) { echo $whole; echo $number; } } Link to comment https://forums.phpfreaks.com/topic/63337-multiple-arrays-in-a-foreach-statement/#findComment-315630 Share on other sites More sharing options...
lehula Posted August 4, 2007 Author Share Posted August 4, 2007 i'll try that, but i doubt that will work, cause that is creating two loops. Link to comment https://forums.phpfreaks.com/topic/63337-multiple-arrays-in-a-foreach-statement/#findComment-315648 Share on other sites More sharing options...
keeB Posted August 4, 2007 Share Posted August 4, 2007 i'll try that, but i doubt that will work, cause that is creating two loops. So? It will work just fine. Link to comment https://forums.phpfreaks.com/topic/63337-multiple-arrays-in-a-foreach-statement/#findComment-315684 Share on other sites More sharing options...
Barand Posted August 4, 2007 Share Posted August 4, 2007 You could try <?php $array = array_combine($tables[1], $tables[2]) foreach ($array as $whole => $number) { echo "$whole : $number<br/>"; } Link to comment https://forums.phpfreaks.com/topic/63337-multiple-arrays-in-a-foreach-statement/#findComment-315685 Share on other sites More sharing options...
ss32 Posted August 4, 2007 Share Posted August 4, 2007 or you could try... <?php foreach ($tables[1] as $k => $i) { echo $i; echo $tables[2][$k]; } ?> Link to comment https://forums.phpfreaks.com/topic/63337-multiple-arrays-in-a-foreach-statement/#findComment-315695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.