jimbeeer Posted August 22, 2012 Share Posted August 22, 2012 Can anyone please help with this. It's late, my eyes are sore and my brain doesn't work any more! I've got 3 variables (value, business_id, bus_id) that cycle through a foreach loop. Here are the results of one particular loop: value:11 business_id:11 bus_id:11 value:11 business_id:11 bus_id:11 value:11 business_id:11 bus_id:11 value:13 business_id:11 bus_id:11 value:13 business_id:11 bus_id:11 value:14 business_id:11 bus_id:11 value:11 business_id:13 bus_id:11 value:11 business_id:13 bus_id:13 value:11 business_id:13 bus_id:13 value:13 business_id:13 bus_id:13 value:13 business_id:13 bus_id:13 value:14 business_id:13 bus_id:13 value:11 business_id:14 bus_id:13 value:11 business_id:14 bus_id:14 value:11 business_id:14 bus_id:14 value:13 business_id:14 bus_id:14 value:13 business_id:14 bus_id:14 value:14 business_id:14 bus_id:14 I only want to display something ONCE each time all 3 values are equal. I'm pretty sure it's not that difficult but it's that time of the evening where my brain has completely fried. Any ideas? I'm sure you have... Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/ Share on other sites More sharing options...
Jessica Posted August 22, 2012 Share Posted August 22, 2012 Code? Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371564 Share on other sites More sharing options...
jimbeeer Posted August 22, 2012 Author Share Posted August 22, 2012 that's what I'm after. I just need a correct 'if' loop with some kind of trigger so it only displays each iteration of all the numbers equalling once. Something along the lines of: if (($bus_id == $row_get_Business['business_id']) && ($value == $row_get_Business['business_id'])) { Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371566 Share on other sites More sharing options...
Drongo_III Posted August 22, 2012 Share Posted August 22, 2012 You could use array_unique to simplify your array - http://php.net/manual/en/function.array-unique.php Then your loop would only have unique values. that's what I'm after. I just need a correct 'if' loop with some kind of trigger so it only displays each iteration of all the numbers equalling once. Something along the lines of: if (($bus_id == $row_get_Business['business_id']) && ($value == $row_get_Business['business_id'])) { Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371578 Share on other sites More sharing options...
Jessica Posted August 22, 2012 Share Posted August 22, 2012 No, POST your CODE. We can't help if you don't show us what you're doing. Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371590 Share on other sites More sharing options...
jimbeeer Posted August 22, 2012 Author Share Posted August 22, 2012 array_unique. That's what I was looking for. Didn't know it existed. Thanks. jesirose: I had no code to show you. At least none that worked. And what I did have would've just complicated things. I was just trying to discover the correct method of doing this. Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371592 Share on other sites More sharing options...
Jessica Posted August 22, 2012 Share Posted August 22, 2012 *headdesk* in your post you said "I've got 3 variables (value, business_id, bus_id) that cycle through a foreach loop. Here are the results of one particular loop:" So clearly you have some code. Whatever is generating this data needs to be fixed. Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371603 Share on other sites More sharing options...
jimbeeer Posted August 22, 2012 Author Share Posted August 22, 2012 It's fixed. Drongo_III was spot on. Quote Link to comment https://forums.phpfreaks.com/topic/267443-how-do-i-only-show-something-once-per-loop/#findComment-1371611 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.