I wanted to set a $levelNumber based on the number of Lessons. So I did the following:
<?php
$s = "Lesson 001: Vocabulary";
preg_match("/([0-9]+)/", $s, $matches);
echo $matches[1]; // => 001
if ($matches[1] >= 060) {
$levelNumber = "2";
} elseif ($matches[1] >= 120) {
$levelNumber = "3";
} elseif ($matches[1] >= 180) {
$levelNumber = "4";
} elseif ($matches[1] >= 240) {
$levelNumber = "5";
} elseif ($matches[1] >= 300) {
$levelNumber = "6";
} elseif ($matches[1] >= 360) {
$levelNumber = "7";
} else {
$levelNumber = "1";
}
?>
But right now no matter how big the lesson is (e.g. 180) $levelNumber always outputs 2. And it outputs 1 when the lesson is under 048. I'm really confused.
This is the correct level with lesson:
Level 1: Lessons 1 to 60
Level 2: Lessons 61 to 120
Level 3: Lessons 121 to 180
Level 4: Lessons 181 to 240
Level 5: Lessons 241 to 300
Level 6: Lessons 301 to 360
Level 7: Lessons 361 to 420
Aucun commentaire:
Enregistrer un commentaire