KeeganWolf Posted May 21, 2009 Share Posted May 21, 2009 I'm trying to create a function I can use inside a loop to sort information when it reaches a certain point in an array. :banghead: This doesn't seem to echo when needed... 1. 2. function yburg(){ 3. $num = intval($data[$j][2]); 4. if ($num == 5){ 5. echo "The PLU number 5 is a Cheesburger";} 6. } 7. for ($j = 0; $j < $count2; $j++) { 8. yburg(); 9. echo $data[$j][2], $data[$j][3], '<br />'; 10. } 11. Where as this does... 1. 2. for ($j = 0; $j < $count2; $j++) { 3. echo $data[$j][2], $data[$j][3], '<br />'; 4. $num = intval($data[$j][2]); 5. if ($num == 5){ 6. echo "The PLU number 5 is a Cheesburger"} 7. } 8. During the loop $data[$j][2] goes from 1 to 144.. Any help for a newcomer to php? Link to comment https://forums.phpfreaks.com/topic/159124-simple-question-about-function-in-loop/ Share on other sites More sharing options...
wildteen88 Posted May 21, 2009 Share Posted May 21, 2009 You should pass $data[$j][2] to your function when you call it. function yburg($num) { if (intval($num) == 5) echo "The PLU number 5 is a Cheesburger"; } for ($j = 0; $j < $count2; $j++) { yburg($data[$j][2]); echo $data[$j][2], $data[$j][3], '<br />'; } Link to comment https://forums.phpfreaks.com/topic/159124-simple-question-about-function-in-loop/#findComment-839186 Share on other sites More sharing options...
KeeganWolf Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks! Link to comment https://forums.phpfreaks.com/topic/159124-simple-question-about-function-in-loop/#findComment-839216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.