I have the following php code which works but it is too long and cumbersome for reading...
// get the row
if ($taktArticle[0]['t1position3'] > 3 AND $taktArticle[0]['t1position3'] < 7 ) {
$row = "row1";
}
if ($taktArticle[0]['t1position3'] > 7 AND $taktArticle[0]['t1position3'] < 12 ) {
$row = "row2";
}
if ($taktArticle[0]['t1position3'] > 12 AND $taktArticle[0]['t1position3'] < 17 ) {
$row = "row3";
}
if ($taktArticle[0]['t1position3'] > 17 AND $taktArticle[0]['t1position3'] < 22 ) {
$row = "row4";
}
if ($taktArticle[0]['t1position3'] > 22 AND $taktArticle[0]['t1position3'] < 27 ) {
$row = "row5";
}
// get the columns
if ($taktArticle[0]['t1position3'] == 3
or $taktArticle[0]['t1position3'] == 8
or $taktArticle[0]['t1position3'] == 13
or $taktArticle[0]['t1position3'] == 18
or $taktArticle[0]['t1position3'] == 23) {
$col = "col1";
}
if ($taktArticle[0]['t1position3'] == 4
or $taktArticle[0]['t1position3'] == 9
or $taktArticle[0]['t1position3'] == 14
or $taktArticle[0]['t1position3'] == 19
or $taktArticle[0]['t1position3'] == 24) {
$col = "col2";
}
if ($taktArticle[0]['t1position3'] == 5
or $taktArticle[0]['t1position3'] == 10
or $taktArticle[0]['t1position3'] == 15
or $taktArticle[0]['t1position3'] == 20
or $taktArticle[0]['t1position3'] == 25) {
$col = "col3";
}
if ($taktArticle[0]['t1position3'] == 6
or $taktArticle[0]['t1position3'] == 11
or $taktArticle[0]['t1position3'] == 16
or $taktArticle[0]['t1position3'] == 21
or $taktArticle[0]['t1position3'] == 26) {
$col = "col4";
}
if ($taktArticle[0]['t1position3'] == 7
or $taktArticle[0]['t1position3'] == 12
or $taktArticle[0]['t1position3'] == 17
or $taktArticle[0]['t1position3'] == 22
or $taktArticle[0]['t1position3'] == 27) {
$col = "col5";
}
Now... I have to repeat this from ($taktArticle[0]['t1position3'] until ($taktArticle[0]['t1position11']
As you understand, code will become huge...Anyone have an idea how this code can be shortened?
Regards, John
you can create functions to clean up the code. There are obvious patterns in your code, looking for those patterns and generalizing those patterns is a key requirement to cleaning up your code. I'm sure a PHP guru could find a more concise way to accomplish this, but a basic example is something like:
function get_row($position) {
$row_ranges = array(
array(3, 7),
array(7, 12),
// etc
);
foreach ($row_ranges as $row_index => $range) {
if ($range[0] < $position && $position < $range[1]) {
return sprtintf('row%s', $row_index + 1)
}
}
}
All the row ranges are kept in a centralized location inside of your function, and there are no more repeated conditionals
function get_column($value) {
// looks like you are starting at 3 and have increments of 5
// 3, 8, 13, 18
// you could loop through and calculate these, or hardcode them in
// use `in_array` to clean up the multiple or statements
if (in_array($value, array(3, 8, 13, 18))) {
}
}
Good answer on the first part by Christoph already.
As for the columns, instead of multiple comparisons inside the IFs, use in_array.
Now... I have to repeat this from ($taktArticle[0]['t1position3'] until ($taktArticle[0]['t1position11']
Your fault for choosing such a sub-optimal data structure.
Why is this data not organized as $taktArticle[0]['t1position'][3] to $taktArticle[0]['t1position'][11], so that you could easily loop over the positions …?
(And if there’s analogues to t1position, so you have t2position, t3position etc. as well – then those should be organized in arrays too.)
My idea would be to make an array an look it up:
$rowtbl = array(4 => 1, 1, 1, 8 => 2, 2, 2, 2);
$row = 'row'.$rowtbl[$taktArticle[0]['t1position3']];
of course the array could get large but you can build something from array_merge and range.
Moreover it seems to me that you could do something like:
$row = ceil(($taktArticle[0]['t1position3']-3)/5);
$col = ($taktArticle[0]['t1position3']-3)%5;
You'd have to check the exact parameters for 3 and 5 (3 would be the starting points and 5 would be the number of cols per row.
In the columns section, rather than joining several OR operators you could check whether your $taktArticle[0]['t1position3'] value is present in an array.
Using PHP in_array (http://php.net/manual/en/function.in-array.php) for example:
if(in_array($taktArticle[0]['t1position3'], [3, 8, 13, 18, 23])) {
$col = "col1";
}
Although this is cleaner, you're still hard-coding all the values in this mapping, so the maintenance overhead will grow as you add new cases.
You can use
if(in_array($taktArticle[0]['t1position3'],array(7,12,17,22,27)))
In place of this type of statement
if ($taktArticle[0]['t1position3'] == 7
OR $taktArticle[0]['t1position3'] == 12
OR $taktArticle[0]['t1position3'] == 17
OR $taktArticle[0]['t1position3'] == 22
OR $taktArticle[0]['t1position3'] == 27)
Or you can do like this
if((((int)$taktArticle[0]['t1position3'])-7)%5==0||((int)$taktArticle[0]['t1position3'])-7)==0)
for this statement
if ($taktArticle[0]['t1position3'] == 7
OR $taktArticle[0]['t1position3'] == 12
OR $taktArticle[0]['t1position3'] == 17
OR $taktArticle[0]['t1position3'] == 22
OR $taktArticle[0]['t1position3'] == 27)
another way is use boolean operators in switch to get row and recursive function to get col
//to get Row:
$m = $taktArticle[0]['t1position3'];
switch($m){
case ($m>3 && $m< 7): $row = 'row1'; break;
case ($m>7 && $m< 12): $row = 'row2'; break;
case ($m>12 && $m< 17): $row = 'row3'; break;
case ($m>17 && $m< 22): $row = 'row4'; break;
case ($m>22 && $m< 27): $row = 'row5'; break;
}
//To get Col
function rootNum($num){
return $num-5>0?rootNum($num-5):$num;
}
$n = rootNum($taktArticle[0]['t1position3']);
$col = 'col' . ($n -2);
There are patterns in there so you can use division instead of arrays:
$temp = $taktArticle[0]['t1position3']-2
if($temp%5 != 0){
$row = "row".ceil(($taktArticle[0]['t1position3']-2)/5);
}
$col = "col".(($taktArticle[0]['t1position3']-2)%5);
Related
I've a client selling wine bottles. He uses boxes with space for 6 bottles, 12 bottles, 18 bottles and 21 bottles. But he only wants to accept orders which fit exactly into these boxes. There must not be any empty space inside.
E.g.
33 is ok: 1x21 and 2x6
48 is ok: 2x21 and 1x6 or 4x12
26 or 35 or 61 are not ok
For my first try was an straight simple way. I produce an array containing a lot of valid numbers, remove duplicates and order them.
$numbers = [];
$end = (int) $bottles/6 + 1;
for ($i=1; $i<=$end; $i++) {
$numbers[] = $i * 6;
$numbers[] = $i * 21;
$numbers[] = $i * 21 + 6;
$numbers[] = $i * 21 + 6 + 6;
$numbers[] = $i * 21 + 6 + 6 + 6;
}
$numbers = array_unique($numbers);
sort($numbers);
It looks like this:
Array
(
[0] => 6
[1] => 12
[2] => 18
[3] => 21
[4] => 24
[5] => 27
[6] => 30
[7] => 33
[8] => 36
[9] => 39
[10] => 42
[11] => 48
[12] => 54
[13] => 60
[14] => 63
....
I can check against my list. ok, fine!
But I want to make a "perfekt" solution fitting for all possible numbers, e.g. I want to know if 123456 is possible. You see, that the array must be very huge for getting this :-)
I tried an equation with 2 unknowns. Why only 2? Because 18 and 12 can be divided by 6. So my approch was:
bottles = 6a + 21b
"a" and "b" must be integer values and may contain zero. "bottles" is an integer value, too. I transformed it to:
bottles / 6 - 3,5b = a
But this doesn't help me to make a good algorithm... I think I'm on the right way, but how can I solve this quite elegant? Where are the algebra gurus? ;-)
To expand on maraca's comment, we're trying to solve the equation x = 6a + 21b over nonnegative integers. Since 6 and 21 are divisible by 3 (the greatest common divisor of 6 and 21), it is necessary that x is divisible by 3. Moreover, if x is less than 21, then it is necessary that x is divisible by 6.
Conversely, if x is divisible by 6, we can set a = x/6 and b = 0. If x is an odd multiple of 3, then x - 21 is divisible by 6; if x is at least 21, we can set a = (x - 21)/6 and b = 1. Every multiple of 3 is either odd or even (and hence divisible by 6), so this proves maraca's equivalence claim.
I found #vivek_23's comment challenging so I figured I would give it a try.
This code will optimize the amount to the smallest number of boxes to fill the order.
It does so by first trying with 21 boxes and if the result is not %6 then it will loop backwards to if it gets a sum that is %6 and split up the rest.
// 99 is challenging since 99 can be divided on 21 to 4, but the remainder is not % 6 (15).
// However the remainder 15 + 21 = 36 which is % 6.
// Meaning the "correct" output should be 3 x 21 + 2 x 18 = 99
$order = 99;
$b = [21 => 0, 18 => 0, 12 => 0, 6 => 0];
// number of 21 boxes possible
if($order >= 21){
$b[21] = floor($order/21);
$order -= $b[21]*21;
}
// if the remainder needs to be modified to be divisible on 6
while($order % 6 != 0){
if($b[21] > 0){
// remove one box of 21 and add the bottles back to the remainder
$order += 21;
$b[21]--;
}else{
// if we run out of 21 boxes then the order is not possible.
echo "order not possible";
exit;
}
}
// split up the remainder on 18/12/6 boxes and remove empty boxes
$b = array_filter(split_up($b, $order));
var_dump($b);
function split_up($b, $order){
// number of 18 boxes possible
if($order >= 18){
$b[18] = floor($order/18);
$order -= $b[18]*18;
}
// number of 12 boxes possible
if($order >= 12){
$b[12] = floor($order/12);
$order -= $b[12]*12;
}
// number of 6 boxes possible
if($order >= 6){
$b[6] = floor($order/6);
$order -= $b[6]*6;
}
return $b;
}
https://3v4l.org/EM9EF
You can reduce this homework to some simpler logic with 3 valid cases:
Multiples of 21.
Multiples of 6.
A combination of the above.
Eg:
function divide_order($q) {
$result['total'] = $q;
// find the largest multiple of 21 whose remainder is divisible by 6
for( $i=intdiv($q,21); $i>=0; $i-- ) {
if( ($q - $i * 21) % 6 == 0 ) {
$result += [
'q_21' => $i,
'q_6' => ( $q - $i * 21 ) / 6
];
break;
}
}
if( count($result) == 1 ) {
$result['err'] = true;
}
return $result;
}
var_dump(
array_map('divide_order', [99, 123456])
);
Output:
array(2) {
[0]=>
array(3) {
["total"]=>
int(99)
["q_21"]=>
int(3)
["q_6"]=>
int(6)
}
[1]=>
array(3) {
["total"]=>
int(123456)
["q_21"]=>
int(5878)
["q_6"]=>
int(3)
}
}
Then you can apply some simple logic to reduce multiple boxes of 6 into boxes of 12 or 18.
function winePacking(int $bottles): bool {
return ($bottles % 6 == 0 || ($bottles % 21) % 3 == 0);
}
https://3v4l.org/bTQHe
Logic Behind the code:
You're working with simple numbers, 6,12,18 can all be covered by mod 6, being that 6 goes into all 3 of those numbers. 21 we can just check a mod 21, and if it's somewhere in between then it's mod 21 mod 6.
Simple as that with those numbers.
What if you do something like so:
function boxes($number) {
if($number >= 21) {
$boxesOfTwentyOne = intval($number / 21);
$remainderOfTwetyOne = floor($number % 21);
if($remainderOfTwetyOne === 0.0) {
return $boxesOfTwentyOne . ' box(es) of 21';
}
$boxesOfTwentyOne = $boxesOfTwentyOne - 1;
$number >= 42 ? $textTwentyOne = $boxesOfTwentyOne . ' boxes of 21, ' : $textTwentyOne = '1 box of 21, ';
$sixesBoxes = floor($number % 21) + 21;
switch (true) {
case ($sixesBoxes == 24):
if($number >= 42) {
return $textTwentyOne . '1 box of 18 and 1 box of 6';
}
return '1 box of 18 and 1 box of 6';
break;
case ($sixesBoxes == 27):
return $boxesOfTwentyOne + 1 . ' box(es) of 21 and 1 box of 6';
break;
case ($sixesBoxes == 30):
if($number >= 42) {
return $textTwentyOne . '1 box of 18 and 1 box of 12';
}
return '1 box of 18 and 1 box of 12';
break;
case ($sixesBoxes == 33):
return $boxesOfTwentyOne + 1 . ' box(es) of 21 and 1 box of 12';
break;
case ($sixesBoxes == 36):
if($number >= 42) {
return $textTwentyOne . '2 boxes of 18';
}
return '2 boxes of 18';
break;
case ($sixesBoxes == 39):
return $boxesOfTwentyOne + 1 . ' box(es) of 21 and 1 box of 18';
break;
default:
return 'Not possible!';
break;
}
} else {
switch (true) {
case ($number == 6):
return '1 box of 6';
break;
case ($number == 12):
return '1 box of 12';
break;
case ($number == 18):
return '1 box of 18';
break;
default:
return 'Not possible!';
break;
}
}
}
EDIT: I have updated my answer, and now I think it is working properly. At least, it passed in all the tests I've made here.
This is actually array items summing up to a target where repetition is allowed problem.
Since in many cases multiple box configurations will come up, you may chose to use the shortest boxes sub list or may be the boxes sublist with the available boxes at hand in real life.
Sorry my PHP is rusty... the below algorithm is in JS but you may simply adapt it to PHP. Of course you may freely change your box sizes to accomodate any number of bottles. So for the given boxes and target 87 we get in total 20 different solutions like
[12,18,18,18,21], [12,12,21,21,21] ... [6,6,6,6,6,6,6,6,6,6,6,21]
function items2T([n,...ns],t){cnt++ //remove cnt in production code
var c = ~~(t/n);
return ns.length ? Array(c+1).fill()
.reduce((r,_,i) => r.concat(items2T(ns, t-n*i).map(s => Array(i).fill(n).concat(s))),[])
: t % n ? []
: [Array(c).fill(n)];
};
var cnt = 0, result;
console.time("combos");
result = items2T([6,12,18,21], 87)
console.timeEnd("combos");
console.log(result);
console.log(`${result.length} many unique ways to sum up to 87
and ${cnt} recursive calls are performed`);
The code is taken from a previous answer of mine.
I want to display output like this:
1 2 3 4
5 6 7 8
9 1 2
I've tried this code:
$num = ['1','2','3','4','....'];
$size = sizeof($num) / 4;
foreach ($num as $key => $value) {
echo $value;
if($key >= round($size){
echo "<br>"
}
}
But the output is like this:
1 2 3 4
5
6
7
8
...
Can anyone suggest how to write the loop?
$num= ['1','2','3','4','5','6','7','8','9'];
$size = sizeof($num) / 4;
foreach ($num as $key => $value){
echo $value;
if(($key+1) % 4 == 0){
echo "<br>";
}
}
You can use modulus instead of round. Cool I didn't know about sizeOf! Good to know. Mark this as the right answer pwease if this works!
Another way to do this if you didn't want to write out all the numbers that are in the Num Array is to just push them into an array with a while loop.
$num= [];
$i = 1;
//Set the Num Variable to have as many numbers as you want without having to manually enter them in
while ($i < 100) {
array_push($num, $i);
$i++;
}
//Run the actual code that adds breaks ever 4 lines
$size = sizeof($num) / 4;
foreach ($num as $key => $value){
echo $value;
if(($key+1) % 4 == 0){
echo "<br>";
}
}
Sorry if this answer looks the same as the first answer but I will explain it clearer
To achieve what you want
Step 1: Create a for loop
The loop will start from 1 to it's total size of the array
for ($x = 1; $x <= sizeof($num); $x++){
}
Then inside your loop
you can use ternary for simplicity
This line of code
# if $x variable is equal to limit number which you wanted to break
# $num[$x-1] -> subtract to by 1 because we know array always start at index 0
if ($x % 4 == 0) {
$num[$x-1]."<br>"; #put a break after it
} else {
echo $num[$x-1];
}
is same as this
echo ($x % 4 == 0) ? $num[$x-1]."<br>" : $num[$x-1];
So try this
<?php
$num= ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'];
$size = sizeof($num) / 4;
for ($x = 1; $x <= sizeof($num); $x++){
echo ($x % 4 == 0) ? $num[$x-1]."<br>" : $num[$x-1];
}
DEMO
You can try this:
$numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8, 19, 20];
$len = 1;
foreach ($numbers as $number) {
echo $number . ' ';
$len++;
if ($len > 4) {
echo '<br>';
$len = 1;
}
}
This is my thought process of how I think it should work.
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) && ($row % 11 != 0)) {
$counter++;
if ($counter % 10 == 0) {
// Do something.
}
}
}
Example of how it should work:
Row 1 = Counter 1
Row 2 = Counter 2
Row 3 = Counter 3
Row 4 = Counter 4
Row 5 = Counter 5
Row 6 = Counter 6
Row 7 = Counter 7
Row 8 = Counter 8
Row 9 = Counter 9
Row 10 = Counter 10
Row 11 = Skip
Row 12 = Counter 11
Row 13 = Counter 12
Row 14 = Counter 13
Row 15 = Counter 14
Row 16 = Counter 15
Row 17 = Counter 16
Row 18 = Counter 17
Row 19 = Counter 18
Row 20 = Counter 19
Row 21 = Counter 20
Row 22 = Skip
Row 23 = Counter 21
etc.
For further reference, here is the full piece of code I've written to remind users on my web-store that if they have 10 tickets in their cart, they'll get the next one free if they add it. Thanks Jakar
$fancyCounter = 1;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$rawCounter++;
if ($rawCounter % 11 !== 0) {
$fancyCounter++;
}
else {
$fancyCounter = 1;
}
}
}
$result->close();
if ($fancyCounter % 11 == 0) {
$freeTicketAvailable = 1;
} else {
$freeTicketAvailable = 0;
}
Here, there is a $rawCounter which counts the rows iterated and a $fancyCounter which keeps the row count just how you posted.
while($row=$result->fetch_assoc()){
$rawCounter++;
if ($rawCounter%11!==0){
$fancyCounter++;
}
if ($rawCounter%10===0){
//Do Something
}
}
Here is an example that give your example output.
If you need the row number and the counter number separate, you could also use a $counter and a $skipCount, and always increment $counter and only increment $skipCount on $counter%11==0 and to get the counter count you want (ie Row 12 = Counter 11, Row 23 = Counter 21), you'd use echo "Row {$counter} = Counter ".($counter-$skipCount)
Try this,
<?php
$counter = 1;
while ($counter <= 33) {
if ($counter % 10 == 0) {
// On 10.
echo "Do Something<br/>";
} else if ($counter % 11 == 0) {
// On 11.
echo "Skip<br/>";
} else {
// Other numbers.
echo $counter . "<br/>";
}
$counter++;
}
?>
You need to replace the condition inside the while(); to suit you.
Output
1
2
3
4
5
6
7
8
9
Do Something
Skip
12
13
14
15
16
17
18
19
Do Something
21
Skip
23
24
25
26
27
28
29
Do Something
31
32
Skip
This should do it. You were trying to divide an array ($row) by a number in your while condition, which is probably undefined even in PHP ;)
if ($result->num_rows > 0) {
$skipCounter = 0;
$tenCounter = 0;
$counter = 0;
while($row = $result->fetch_assoc()) {
++$skipCounter;
if ($skipCounter == 11) {
$skipCounter = 0;
continue;
}
++$counter
++$tenCounter;
echo "Counter: ".$counter;
if ($tenCounter == 10) {
$tenCounter = 0;
echo "Do something";
}
}
}
I have managed to create an algorithm to check the rank of a poker hand. It works 100% correctly, but it's very slow. I've been analysing the code, and the check straight function is one of the slowest parts of it.
So my question is, is there a better way of calculating whether a hand make a straight?
Here is some details:
7 cards, 2 from holder, 5 from board. A can be high or low.
Each card is assigned a value:
2 = 2
3 = 3
..
9 = 9
T = 10
J = 11
Q = 12
K = 13
A = 14
The script has an array of all 7 cards:
$cards = array(12,5,6,7,4,11,3);
So now I need to be able to sort this into an array where it:
discards duplicates
orders the card from lowest to highest
only returns 5 consecutive cards I.e. (3,4,5,6,7)
It needs to be fast; loops and iterations are very costly. This is what I currently use and when it tries to analyse say 15000 hands, it takes its toll on the script.
For the above, I used:
discard duplicates (use array_unique)
order cards from lowest to highest (use sort())
only return 5 consecutive cards (use a for loop to check the values of cards)
Does anyone have any examples of how I could improve on this? Maybe even in another language that I could perhaps look at and see how it's done?
Instead of working with array deduping and sorting, consider using a bitmask instead, and setting bits to 1 where the card value is set. A bitmask works like a Set datastructure and comes with additional advantages when it comes to detecting contiguous elements.
for ($i = 0; $i < count($cards); $i++) {
$card = $cards[$i];
// For each card value, set the bit
if ($card == 14) {
// If card is an ace, also set bit 1 for wheel
$cardBitmask |= 0x2;
}
$cardBitmask |= (1 << $card);
}
// To compare, you simply write a for loop checking for 5 consecutive bits
for($i = 10; $i > 0; $i--)
{
if ($cardBitmask & (0x1F << $i) == (0x1F << $i)) {
// Straight $i high was found!
}
}
Consider the Java implementation at this link. I've included it here:
public static boolean isStraight( Card[] h )
{
int i, testRank;
if ( h.length != 5 )
return(false);
sortByRank(h); // Sort the poker hand by the rank of each card
/* ===========================
Check if hand has an Ace
=========================== */
if ( h[4].rank() == 14 )
{
/* =================================
Check straight using an Ace
================================= */
boolean a = h[0].rank() == 2 && h[1].rank() == 3 &&
h[2].rank() == 4 && h[3].rank() == 5 ;
boolean b = h[0].rank() == 10 && h[1].rank() == 11 &&
h[2].rank() == 12 && h[3].rank() == 13 ;
return ( a || b );
}
else
{
/* ===========================================
General case: check for increasing values
=========================================== */
testRank = h[0].rank() + 1;
for ( i = 1; i < 5; i++ )
{
if ( h[i].rank() != testRank )
return(false); // Straight failed...
testRank++; // Next card in hand
}
return(true); // Straight found !
}
}
A quick Google search for "check for poker straight (desired_lang)" will give you other implementations.
You could just sort the cards and loop over them in an array - saving always the last card and compare them with the current one.
$cards = array(12,5,6,7,4,11,3);
sort($cards);
$last = 0;
$count = 0;
$wheel = false;
foreach ($cards as $card) {
if ($card == $last) {
continue;
} else if ($card == ++$last) {
$count++;
} else {
if ($last == 6) $wheel = true;
$count = 1;
$last = $card;
}
if ($count == 5 || ($card == 14 && $wheel)) {
echo "straight $last";
$straight = range($last - 4, $last);
break;
}
}
You may go like this, you don't need to sort or anything (assuming that 2 is 2 and 14 is ace):
$cards = [12,5,6,7,4,11,3];
function _inc(&$i) {
if ($i == 14)
$i = 2;
else
$i++;
return $i;
}
$straight = false;
for($i = 2; $i <= 14; $i++) {
$ind = $i;
if (!in_array($ind, $cards)) continue;
$s = [$ind, _inc($ind), _inc($ind), _inc($ind), _inc($ind)];
$straight = count(array_intersect($s, $cards)) == count($s);
if ($straight) break;
}
print $straight;
Simple question: what's a more compact way to write a conditional like the following:
if ($i != 8 && $i != 19 && $i != 23 && $i != 43) ...
I tried the following approaches with no luck:
if ($i != 8 || 19 || 23 || 43) ...
if ($i != 8 or 19 or 23 or 43) ...
You could collect all of those numbers into an array
$set = array(8, 19, 23, 43);
And then test the value against the set using the in_array() function
if (in_array($i, $set)) { ... }
For this just make array of numbers like bellow
$num = array(8,19,23,43);
and check in_array like bellow.
<?php
$num = array(8,19,23,43);
if(!in_array($i,$num)){
echo "here";
}
?>