I trying to get the following type of code to work, with little success. How do I get the conditional to kick in only if $j = 3 or 5. At the moment the script is always echoing success. <?php $j = 6; $primes = 3||5; if ($j == $primes) { echo "success"; } else { echo "failure"; } ?> PHP: The real use is within a for loop, it's just that I can't work out how to get it going with an or.
Or you can use in_array() function <?php $j = 6; $primes = array(3,5); if (in_array($j, $primes)) { echo "success"; } else { echo "failure"; } ?> Code (php):
using in_array is a better solution, becuase with this code you can expand your list of prime numbers simply by adding new numbers in the array.
I have used the in_array function due to it being easier to use and easier to expand upon. Thanks for the idea