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; } Quote 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; } } Quote 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. Quote 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. Quote 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/>"; } Quote 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]; } ?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.