deadliver Posted September 20, 2012 Share Posted September 20, 2012 $Stats_Cats = array("Battles","Victories","Defeats"); $Stats = array(); function GetStats($curlstr){ foreach($CategoriesMajor as $key =>$value) { [s] $str = '<td class=""> '.$value.': </td>'; $str = get_part($curlstr,$str,'</tr>'); $str = get_part($str,'<td class="td-number-nowidth">','</td>'); $str = preg_replace ( "'<[^>]+>'U", "", $str); $str = strip_tags($str);[/s] //add value to the item in the array $Stats[$value]=$str; } return $Stats; } //$string is my return from a web scrape using curl library GetStats($string); When I test this foreach loop outside of this function it works fine. When I embed it into the function and call it, it does not begin the loop. I am not concerned about the code inside the foreach statement since it has yet to even try to loop. Quote Link to comment https://forums.phpfreaks.com/topic/268620-foreach-within-function-help/ Share on other sites More sharing options...
shlumph Posted September 20, 2012 Share Posted September 20, 2012 That's because the function has no idea where $CategoriesMajor came from. Quote Link to comment https://forums.phpfreaks.com/topic/268620-foreach-within-function-help/#findComment-1379696 Share on other sites More sharing options...
deadliver Posted September 20, 2012 Author Share Posted September 20, 2012 Brilliant. I feel so stupid posting but I have been staring at it for 3 days. Thanks so much for the help again. Quote Link to comment https://forums.phpfreaks.com/topic/268620-foreach-within-function-help/#findComment-1379699 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.