tobeyt23 Posted February 5, 2009 Share Posted February 5, 2009 With the below I would like to get them to return true if grades 9-12, 6-8 or 1-5 respectfully. This doesn't seem to work! <?php preg_match('/[{9}{10}{11}{12}]/',$book['grade_level']) preg_match('/[{6}{7}{8}]/',$book['grade_level']) preg_match('/[{1}{2}{3}{4}{5}]/',$book['grade_level']) ?> Link to comment https://forums.phpfreaks.com/topic/143970-preg_match-help/ Share on other sites More sharing options...
wildteen88 Posted February 5, 2009 Share Posted February 5, 2009 Does $grade_level contain just a number eg, 10 If so you can do if($grade_level >= 9 && $grade_level <= 12) { // grade level is 9 to 12 } elseif($grade_level >= 6 && $grade_level <= { // grade level is 6 to 8 } elseif($grade_level >= 1 && $grade_level <= 5) { // grade level is 1 to 5 } else { // grade level is unknown. } Link to comment https://forums.phpfreaks.com/topic/143970-preg_match-help/#findComment-755440 Share on other sites More sharing options...
DarkWater Posted February 5, 2009 Share Posted February 5, 2009 @wildteen: No, you can't do if (something >= 1 && <= 2). You need to list the variable twice. <?php $grade_level = 10; if ($grade_level >= 9 && $grade_level <= 12) { .... Link to comment https://forums.phpfreaks.com/topic/143970-preg_match-help/#findComment-755441 Share on other sites More sharing options...
wildteen88 Posted February 5, 2009 Share Posted February 5, 2009 @wildteen: No, you can't do if (something >= 1 && <= 2). You need to list the variable twice. <?php $grade_level = 10; if ($grade_level >= 9 && $grade_level <= 12) { .... Oops! Yea sorry about that. Shouldn't be typing and watching TV at the same time. I'll correct my post. Link to comment https://forums.phpfreaks.com/topic/143970-preg_match-help/#findComment-755443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.