variable dynamic span overlap - php

$lines = file("res_example.txt");
$resArr = array();
foreach ($lines as $line_num => $line) {
$columns = explode("\t", $line);
$raws = $columns['1'];
$hits = $columns['2'];
$names = $columns['0'];
$models = $columns['3'];
$colors = $columns['4'];
$allModels[$models] = 1;
$resArr[] = array(
name => $names,
score => $raws,
hit => $hits,
model => $models,
color => $colors
);
}
$seqArr = array('A', 'T', 'C', 'G');
$randseq = array();
for ($i = 0; $i < 1000; $i++) {
$randseq[] = $seqArr[array_rand($seqArr)];
}
$res = "";
echo "<div id=\"coltext\" style=\"font-family:monospace;\">";
foreach ($allModels as $modName => $value) {
echo "<input ModelName=$modName type=\"checkbox\"
checked==\"TRUE\" onclick=\"toggle.apply(this)\" />$modName";
}
echo "<hr />";
$score = rawtransform($raw);
foreach ($randseq as $index => $nuc) {
$index = $index + 1;
foreach ($resArr as $hitArr) {
$hit = $hitArr['hit'];
$raw = $hitArr['score'];
$model = $hitArr['model'];
$colval = $hitArr['color'];
$score = rawtransform($raw);
$color = getcolor($score, $colval);
if (($hit+3) == $index) {
echo "</span>";
}
if ($hit == $index) {
echo "<span class=$model Title=\"position:$index,score:$raw\"
style=\"background:$color;\" color=\"$color\">";
//problem when theres overlap !?
}
}
echo $nuc;
if (($index%50)==0){
echo"<br />";
}
}
echo "</div>";
function rawtransform($raw) {
return (int)($raw/50)-9;
}
function getcolor($score,$ArrayModelval)
{
switch ($score){
// working. test each color.
case 1: /*500-550(Raw Score)*/
$col=$ArrayModelval;
return"hsl( $col,100%,90%)";
break;
case 2: //550-600
$col=$ArrayModelval;
return "hsl( $col,100%,85%)";
break;
case 3: //600-650
$col=$ArrayModelval;
return "hsl( $col,100%,85%)";
break;
case 4: //650-700
$col=$ArrayModelval;
return"hsl( $col,100%,80%)";
break;
case 5: //700-750
$col=$ArrayModelval;
return"hsl( $col,100%,70%)";
break;
case 6: //750-800
$col=$ArrayModelval;
return "hsl( $col,100%,60%)";
break;
case 7: //800-850
$col=$ArrayModelval;
return "hsl( $col,100%,50%)";
break;
case 8: //850-900;
$col=$ArrayModelval;
return "hsl( $col,100%,50%)";
break;
case 9: //900-950
$col=$ArrayModelval;
return "hsl( $col,100%,40%)";
break;
case 10: //950-1000
$col=$ArrayModelval;
return "hsl($col,100%,40%)";
break;
}
}
For the most part does what I want: I want to color parts of the random seqeunce where there is a $hit - defined on external file. My only problem is when there is any overlap, i.e. if two hits are within 3 bases of each other the span is elongated and colored as if its one span.
The external file has a position to start a span which have variable colors depending on a score given in the external file. Basically if I have 3 results, 2 of which have almost the same hit (+-1) and the other a different hit, I would only see two sections colored, can anyone see what my problem is? Sorry I know I probably worded this horribly but its hard to explain. Thanks.
>chr1:2198584545754_genome_1000+ 500 1000 Model1 0
>chr2:2198581212154_genome_1000+ 510 992 Model2 180
>chr3:2115151215754_genome_1000+ 520 990 Model3 330
>chr4:2198584545754_genome_1000+ 530 980 Model3 330
>chr5:1218455145754_genome_1000+ 540 970 Model2 180
>chr6:1231354645454_genome_1000+ 550 960 Model1 0
>chr7:1231213211134_genome_1000+ 600 950 Model3 330
>chr7:1231213211134_genome_1000+ 650 940 Model3 330
javascript:
function toggle() {
var div= document.getElementById('coltext');
var modName=this.getAttribute('ModelName');
var spans=div.getElementsByTagName('span');
var spans_l=spans.length;
while (spans_l--){
span=spans[spans_l];
if(span.getAttribute('class')==modName && this.checked==true){
var color= span.getAttribute('color');
span.style.background=color;
}
if(span.getAttribute('class')==modName && this.checked==false){
span.style.background="white";
}
}
}

Try this on for size. It works by using a FIFO stack $currentHits to handle the hit boundaries. I have also added a few helper functions to deal with color generation - if you alter your getcolor() function to return an array instead of a CSS string one of them could be dropped, making it more efficient.
I have been unable to test this because I don't have the source code for your getcolor() or rawtransform() functions - if you add these to the question I am certain further improvements can be made and I can test the code properly. Also, it would be good to see what your CSS Model1, Model2 etc classes look like.
Edit: now includes getcolor()/rawtransform() functions and (at least partially) tested
<?php
function rawtransform ($raw) {
return (int) ($raw / 50) - 9;
}
function getcolor ($score, $h) {
switch ($score) {
// working. test each color.
case 1: /*500-550(Raw Score)*/
$l = 90;
break;
case 2: case 3: //550-650
$l = 85;
break;
case 4: //650-700
$l = 80;
break;
case 5: //700-750
$l = 70;
break;
case 6: //750-800
$l = 60;
break;
case 7: case 8: //800-900;
$l = 50;
break;
case 9: case 10: default: //900-1000 / out of range
$l = 40;
break;
}
return array(
'h' => $h,
's' => 100,
'l' => $l
);
}
function hsl_average_color () {
// Takes an unlimited number of arguments, calculates the average HSL value and returns a CSS string
$args = func_get_args();
$h = $s = $l = array();
foreach ($args as $arg) {
$h[] = $arg['h'];
$s[] = $arg['s'];
$l[] = $arg['l'];
}
return sprintf('hsl(%d, %d%%, %d%%)', (int) round(array_sum($h) / count($h)), (int) round(array_sum($s) / count($s)), round(array_sum($l) / count($l)));
}
$fileName = 'res_example.txt';
// Open the file
if (!$fp = fopen($fileName, 'r')) {
// Handle file read errors here
die("Unable to open file $fileName");
}
// Loop the file data and build an associative array
$resArr = array();
while (($line = fgetcsv($fp, 0, "\t")) !== FALSE) {
// You didn't declare $allModels as an empty array before the loop
// Should you have?
$allModels[$line[3]] = 1;
// Note that I have dropped the hit key and instead keyed the outer
// array by this value. I have added an end key to track the end of
// a hit
$resArr[$line[2]] = array(
'name' => $line[0],
'score' => $line[1],
'end' => $line[2] + 4,
'model' => $line[3],
'color' => getcolor(rawtransform($line[1]), $line[4])
);
}
// Close the file
fclose($fp);
// Generate a random sequence
$seqArr = array('A', 'T', 'C', 'G');
$randseq = array();
for ($i = 0; $i < 1000; $i++) {
$randseq[] = $seqArr[array_rand($seqArr)];
}
// $res appears to do nothing in you code
// $res = "";
// Open the <div>
echo '<div id="coltext" style="font-family:monospace;background-color:#000000;color:#FFFFFF;">'."\n";
// Iterate over $allModels and echo checkboxes
foreach ($allModels as $modName => $value) {
// ModelName is a non-standard HTML attribute, are you sure you meant to do this?
echo '<input ModelName="'.$modName.'" type="checkbox" checked="checked" onclick="toggle.apply(this);" />'.$modName."\n";
}
echo "<hr />\n";
// This line does nothing useful here
// $score = rawtransform($raw);
// An array to track the current hits
$currentHits = array();
foreach ($randseq as $index => $nuc) {
// Increment $index
$index++;
// Track whether we are in a hit/reached a boundary
$boundary = FALSE;
$inHit = (bool) count($currentHits);
// Check whether we are at the end of the lowest hit in the stack
if ($inHit && $index == $currentHits[0]['end']) {
$boundary = TRUE;
array_shift($currentHits);
}
// Check whether we are at the start of a new hit
if (isset($resArr[$index])) {
$boundary = TRUE;
$currentHits[] = $resArr[$index];
}
// If we reached a boundary
if ($boundary) {
// Close a hit
if ($inHit) {
echo "</span>";
}
// Open a hit
if (count($currentHits)) {
// Get the current color value
$colors = array();
foreach ($currentHits as $hit) $colors[] = $hit['color'];
$color = call_user_func_array('hsl_average_color', $colors);
// Start a new span
echo '<span class="'.$currentHits[0]['model'].'" title="position:'.$index.',score:'.$currentHits[0]['score'].'" style="color: '.$color.';">';
}
}
// Print the character
echo $nuc;
// Split into 50 character chunks
if (!($index % 50)){
echo"<br />\n";
}
}
// Close the last span if one is still open
if (count($currentHits)) {
echo "</span>";
}
// Close the <div>
echo "</div>\n";

Related

How get a (fixed) value based on number range

I have a number, e.g. $humidity
I need to check value of this number and get a fixed value if number is in a predetermined range.
E.g.
if ($humidity<30) {
return 'dry';
}
if ($humidity>=30 && $humidity <=40) {
return 'wet'
}
if ($humidty>40 && $humidity<70) {
return 'confortable'
}
And so on.
Is there another possibility to don't use 4/5 different if ?
As long as you process the values in order, you don't need both the upper and lower values of each range. Then you can utilize short-circuiting and just put everything in a loop:
function nameOf($humidity)
{
$list = [
30 => 'dry',
40 => 'wet',
70 => 'comfortable',
];
foreach ($list as $value => $name) {
if ($humidity < $value) {
return $name;
}
}
return 'default';
}
I think switch is great for this usage:
$result = null;
switch(true) {
case $humidity < 30:
$result = 'dry';
break;
case $humidity >= 30 && $humidity < 40:
$result = 'wet';
break;
case $humidty > 40 && $humidity < 70:
$result = 'comfortable';
break;
}
return $result;
you can create an range array for your temps and then array_walk that to find the right range.
$h=40;
$harr = [ 0 => 'dry', 1 => 'wet', 2 => 'confy'];
$range = array_flip(range(0, 100, 30));
array_walk($range, 'findHumidity', $range);
var_dump($harr[$result]);
function findHumidity($value, $key, $r){
global $h; //if you using a class and properties you can ignore these two lines
global $result;
$normalRange = array_flip($r);
if($h> $key && $normalRange[$value+1]!=null && $h<= $normalRange[$value+1]){
$result = $value;
}
}
Working example: https://3v4l.org/fWLDu (a simplified version: https://3v4l.org/ROjWk)
or you can define the range array manually like here: https://3v4l.org/B0oTU

Using unique random numbers for a switch statement

I need a function or an array that gives me random numbers from 1 - 47, so I can use it for my code below.
public function output($question_id, $solution) {
$yes = ($GLOBALS['TSFE']->sys_language_uid == 0) ? 'Ja' : 'Oui';
$no = ($GLOBALS['TSFE']->sys_language_uid == 0) ? 'Nein' : 'No';
switch ($question_id) {
case 1:
$arg = array(
'main_content' => $this->build_html(1, '01_0429_04_14_Psori_Arthro.jpg', $yes, $no, $solution)
);
break;
case 2:
$arg = array(
'main_content' => $this->build_html(2, '02_0342_05_14_Psori_Arthropathie.jpg', $yes, $no, $solution),
);
break;
case 3:
$arg = array(
'main_content' => $this->build_html(3, '03_0255_05_14_Psori_Arthropathie.jpg', $yes, $no, $solution),
);
break;
}
}
Example
This
case 1:
$arg = array(
'main_content' => $this->build_html(1, '01_0429_04_14_Psori_Arthro.jpg', $yes, $no, $solution)
);
should look somehow like this:
case $random_id:
$arg = array(
'main_content' => $this->build_html($random_id, '01_0429_04_14_Psori_Arthro.jpg', $yes, $no, $solution)
);
So that means, each case and each first parameter of the function build_html should get a unique random id.
Of course I could use rand() but then it is quite possible that I get duplicated values.
Any help would be appreciated!
Create a class like follows:
class SamplerWithoutReplacement {
private $pool;
public __construct($min,$max) {
$this->pool = range($min,$max);
}
public function next() {
if (!empty($this->pool)) {
$nIndex = array_rand($this->pool);
$value = $this->pool[$nIndex];
unset($this->pool[$nIndex]);
return $value;
}
return null; //Or throw exception, depends on your handling preference
}
}
Use it as:
$sampler = new SamplerWithoutReplacement(1,47);
//do things
$value = $sampler->next();
The $sampler will draw random samples between 1-47 without replacing them in the pool and therefore they'll be unique.
Not tested but I think it should work:
$numbers = [];
function genenerate_nr_not_in_list($list, $min = 1, $max = 47) {
$number = rand($min, $max);
while (false !== array_search($number, $list)) {
$number = rand($min, $max);
}
return $number;
}
for ($i = 0; $i < 47; $i++) {
$numbers[] = genenerate_nr_not_in_list($numbers);
}
With this solution you can generate numbers in each range ($min and $max parameters). But it should be at least as big as the number of values you need ($max).

Incrementing through a MYSQL result set without stopping

I am trying to increment through a result set from my table.
I attempt to display the next three results using an increment. This is working fine.
For example;
current = 5.
It then displays the next three: 6,7,8
It can also display the previous three: 4,3,2
The problem comes when I reach the last couple or minimum couple of results. It will currently stop;
current = 23
next: 24, 25
I cannot figure out to loop through to the last or first few results.
E.g. I want it to do this:
current = 2
display previous three: 1, 25, 24
AND FOR next:
current = 23:
display next three: 24, 25, 1
I'm returning these as arrays. Code:
$test_array = array();
$no = 1;
while($results=mysql_fetch_assoc($test_query))
{
$test_array[] = array('test_id' => $results['id'],
'path' => $results['Path'],
'type' => $results['FileType']
'no' => $no);
$no++;
}
$current_no = 0;
if(is_array($test_array) && count($test_array)>0)
{
foreach($test_array as $key=>$array)
{
if($array['test_id']==intval($db_res['current_id']))
{
$current[] = $array;
$current_no = intval($key+1);
}
else
//error
if(intval($current_no)>0)
{
//Next 3
for($i=0;$i<3;$i++)
{
if(isset($test_array[intval($current_no+$i)]) && is_array($test_array[intval($current_no+$i)]))
{
$next[] = $test_array[intval($current_no+$i)];
}
else
break;
}
//Previous 3
for($i=2;$i<5;$i++)
{
if(isset($test_array[intval($current_no-$i)]) && is_array($test_array[intval($current_no-$i)]))
{
$previous[] = $test_array[intval($current_no-$i)];
}
else
break;
}
break;
}
else
//error
}
}
else
//error
If anyone has any ideas on how to help, that would be great!
Find $key for $current and set $next_key = $prev_key = $key;
Find last key $max = count($test_array) - 1;
Increase $next_key & decrease $prev_key 3 times (and check if
boundary is reached):
Loop might look like this.
for ($i = 1; $i <= 3; $i++)
{
$next_key = ($next_key == $max) ? 0 : $next_key + 1;
$prev_key = ($prev_key == 0) ? $max : $prev_key - 1;
$next[] = $test_array[$next_key];
$prev[] = $test_array[$prev_key];
}

Set condition in wordsearch so letters of words will not intersect with each other?

I'm trying to make a wordsearch game using php. First I will create the table/grid and then populate the table with random letters and then I will replace the random letters with the letters of the words as well as determining the direction of the words either HORIZONTAL, VERTICAL or DIAGONAL. The problem is, the letters of words intersect with each other, which messed up the table. The questions are,
How to set condition where in letters of words will not intersect with each other
How to determine if the current position is already occupied by the other words letter?
I'm having problem with the letters of words they keep intersecting with each other.
Any idea?
$row = 5;
$col = 5;
$characters = range('a','z');
$max = count($characters) - 1;
$rc = array();
for ($r=1;$r<=$row;$r++)
{
for ($c=1;$c<=$col;$c++)
{
$rc['r'.$r.'c'.$c] = $characters[mt_rand(0,$max)];
$fill['r'.$r.'c'.$c] = '';
}
}
$directions = array('H', 'V', 'D');
$wrdList =array('four', 'data', 'howl');
foreach ($wrdList as $wrd)
{
$wrdLen = strlen($wrd);
$dir = $directions[mt_rand(0,2)];
if ($dir =="H" or $dir=="D" )
{
$limitRow = $row - $wrdLen+1;
$limitCol = $col - $wrdLen+1;
$startPointRow = 1;
$startPointCol = 1;
}
elseif ($dir=="V")
{
$limitRow = $row - $wrdLen + 1;
$limitCol = $col;
$startPointRow = 1;
$startPointCol = 1;
}
$temprow = mt_rand($startPointRow,$limitRow);
$tempcol = mt_rand($startPointCol,$limitCol);
while($wrdLen >0)
{
$thisChar= substr($wrd,0,1);
$wrd = substr($wrd,1);
$wrdLen--;
$x = 'r'.$temprow.'c'.$tempcol;
$rc[$x] = $thisChar;
$fill[$x] = '#2952f8';
if($dir=="D")
{
$tempcol++;
$temprow++;
}
elseif($dir=="V")
{
$temprow++;
}
elseif($dir=="H")
{
$tempcol++;
}
}
}
#--Display the random letters and the words
echo '<table style="border:1px solid #000">';
for ($r=1;$r<=$row;$r++)
{
echo '<tr style="border:1px solid #000">';
for ($c=1;$c<=$col;$c++)
{
$thisChar=$rc['r'.$r.'c'.$c];
$fills = $fill['r'.$r.'c'.$c];
echo '<td style="border:1px solid #000; background-color: '.$fills.'">';
echo $thisChar;
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
You're doing it backwards. First put in the words you want, then put in the random letters.
Before you put in each successive word, choose the random path for that word, and then along that path, check that there aren't any non-matching letters. (E.g. if 'alphabet' crosses the word 'graph' in a place where they both have a letter 'a', it's okay; otherwise, find a different spot for 'alphabet'). Finally, after all the words are in place, go through the whole thing and put random letters in the spots that don't have letters. Or, if you can't find a place for all the words, start over again.
EDIT:
How to find letters in particular spots. Okay. So, taking a look at your code, you are doing something illogical here:
$rc['r'.$r.'c'.$c] = $characters[mt_rand(0,$max)];
You are creating a one-dimensional array out of, essentially, the product of two keys. Instead, you want to do a two-dimensional array. This makes complete sense because a) you have two keys, and b) word searches have two dimensions.
$rc[$r][$c] = $characters[mt_rand(0,$max)];
So, let's start at the beginning with everything rearranged. Please note that I have rewritten things to start your row/column count at 0 instead of 1 because that's the programming convention for arrays, and I'm not going to try to bend my brain around counting from 1 just for this.
$wrdList =array('four', 'banana', 'howl');
$row = 5; //six rows counting from 0
$col = 5; //six columns counting from 0
$rc = array(); //our tableau array
$directions = array('H', 'V', 'D');
foreach ($wrdList as $wrd)
{
$found = false; // by default, no spot has been found
$tries = $row*$col; // we will try a reasonable number of times to find a spot
while(!$found && $tries > 0) {
$wrdLen = strlen($wrd);
$dir = $directions[mt_rand(0,2)];
if ($dir =="H")
{
$limitRow = $row;
$limitCol = $col - ($wrdLen - 1);
}
elseif($dir=="D")
{
$limitRow = $row - ($wrdLen - 1);
$limitCol = $col - ($wrdLen - 1);
}
elseif ($dir=="V")
{
$limitRow = $row - ($wrdLen - 1);
$limitCol = $col;
}
$temprow = mt_rand(0,$limitRow);
$tempcol = mt_rand(0,$limitCol);
//this is my temporary placement array
$placement = array();
//let's use for loop so we can capitalize on having numeric keys
$r = $temprow;
$c = $tempcol;
for($w = 0; $w < $wrdLen; $w++) {
$thisChar = $wrd{$w};
//find array keys
if($dir == 'V' || $dir == 'D') {
$r = $temprow + $w;
}
if($dir == 'H' || $dir == 'D') {
$c = $tempcol + $w;
}
//look at the current tableau
if(isset($rc[$r][$c])) { //the intended spot has a letter
if($rc[$r][$c] == $thisChar) { //the intended spot's letter is the same
$placement[$r][$c] = $thisChar;
if($w == $wrdLen-1) { // this is the last letter
$found = true; // we have found a path
}
} else {
break; //this path doesn't work
}
} else {
$placement[$r][$c] = $thisChar;
if($w == $wrdLen-1) { // this is the last letter
$found = true; // we have found a path
}
}
}
if($found) {
//put the letters out of the temporary array and into the tableau
foreach($placement as $r=>$set) {
foreach($set as $c=>$letter) {
$rc[$r][$c] = $letter;
}
}
}
$tries--;
}
//handle the error where no spot was found for the word
if(!$found) {
//your error handling here
}
}
//random fillers
$characters = range('a','z');
$max = count($characters) - 1;
for($r = 0; $r <= $row; $r++) {
for($c = 0; $c <= $col; $c++) {
if(!isset($rc[$r][$c])) {
$rc[$r][$c] = $characters[mt_rand(0,$max)];
}
}
}

php switch case statement to handle ranges

I'm parsing some text and calculating the weight based on some rules. All the characters have the same weight. This would make the switch statement really long can I use ranges in the case statement.
I saw one of the answers advocating associative arrays.
$weights = array(
[a-z][A-Z] => 10,
[0-9] => 100,
['+','-','/','*'] => 250
);
//there are more rules which have been left out for the sake of clarity and brevity
$total_weight = 0;
foreach ($text as $character)
{
$total_weight += $weight[$character];
}
echo $weight;
What is the best way to achieve something like this?
Is there something similar to the bash case statement in php?
Surely writing down each individual character in either the associative array or the switch statement can't be the most elegant solution or is it the only alternative?
Well, you can have ranges in switch statement like:
//just an example, though
$t = "2000";
switch (true) {
case ($t < "1000"):
alert("t is less than 1000");
break
case ($t < "1801"):
alert("t is less than 1801");
break
default:
alert("t is greater than 1800")
}
//OR
switch(true) {
case in_array($t, range(0,20)): //the range from range of 0-20
echo "1";
break;
case in_array($t, range(21,40)): //range of 21-40
echo "2";
break;
}
$str = 'This is a test 123 + 3';
$patterns = array (
'/[a-zA-Z]/' => 10,
'/[0-9]/' => 100,
'/[\+\-\/\*]/' => 250
);
$weight_total = 0;
foreach ($patterns as $pattern => $weight)
{
$weight_total += $weight * preg_match_all ($pattern, $str, $match);;
}
echo $weight_total;
*UPDATE: with default value *
foreach ($patterns as $pattern => $weight)
{
$match_found = preg_match_all ($pattern, $str, $match);
if ($match_found)
{
$weight_total += $weight * $match_found;
}
else
{
$weight_total += 5; // weight by default
}
}
You can specify the character range using regular expression. This saves from writing a really long switch case list. For example,
function find_weight($ch, $arr) {
foreach ($arr as $pat => $weight) {
if (preg_match($pat, $ch)) {
return $weight;
}
}
return 0;
}
$weights = array(
'/[a-zA-Z]/' => 10,
'/[0-9]/' => 100,
'/[+\\-\\/*]/' => 250
);
//there are more rules which have been left out for the sake of clarity and brevity
$total_weight = 0;
$text = 'a1-';
foreach (str_split($text) as $character)
{
$total_weight += find_weight($character, $weights);
}
echo $total_weight; //360
Much different ways to do this.
$var = 0;
$range_const = range(10,20);
switch ($var) {
case 1: $do = 5; break; # 1
case 2: $do = 10; break; # 2
case 3:
case 4:
case 5: $do = 15; break; # 3, 4, 5
default:
if ($var > 5 && $var < 10) { # High performance (6..9)
$do = 20;
} else if (in_array($var, $range_const, true)) { # Looks clear (10..20)
$do = 25;
} else { # NOT in range 1..20
$do = -1;
}
}
print($do);
There no direct range X..Y compares because $var checks to true in each step, but this allows do some nice cheating like this...
$in = create_function('$a,$l,$h', 'return $a>=$l && $a<=$h;');
$var = 4;
switch (true) {
case ($var === 1): echo 1; break;
case ($var === 2): echo 2; break;
case $in($var, 3, 5): echo "3..5"; break;
case $in($var, 6, 10): echo "6..10"; break;
default: echo "else";
}
If you have a more complex conditions, you can wrap them inside a function. Here's an oversimplified example:
$chartID = 20;
$somethingElse = true;
switch (switchRanges($chartID, $somethingElse)) {
case "do this":
echo "This is done";
break;
case "do that":
echo "that is done";
break;
default:
echo "do something different";
}
function switchRanges($chartID, $somethingElse = false)
{
if (in_array($chartID, [20, 30]) && $somethingElse === true) {
return "do this";
}
if (in_array($chartID, [20, 50]) && $somethingElse === false) {
return "do that";
}
}
I think I would do it in a simple way.
switch($t = 100){
case ($t > 99 && $t < 101):
doSomething();
break;
}

Categories