I’m running a foreach loop for the whole script that checks 9 things.
Let’s say five of them have value “a” and four of them have value “b”.
How do I write an IF condition (or something) that only returns “a” and “b” once?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simple method (check last value)
Use a variable which stores the previous contents, and compare it with the current iteration (only works if the similar items are sequential)
More robust method (store used values on an array)
Or, if you have complex objects, where you need to check an inner property and the like things are not sequential, store the ones used onto an array:
For example (1):
For example (2)