Skip to content
Advertisement

Setup a whole range of PHP if statements for code to pull from

I have a whole bunch of values, that need to correspond to some other values. I’ve so far setup an array as per the below:

JavaScript

I also have a variable, $input that provides a number value.

I need to figure out a way to say something like:

JavaScript

My array list will end up having hundreds of values in it, so if there is a much better way to achieve this I’m all ears. It just must be in PHP.

How could this best be achieved? Many thanks for any help in advance!

Advertisement

Answer

This can be accomplished quite easily using the isset function:

JavaScript

To find within a range:

JavaScript

Note: This code would blow up if you accidentally had ranges overlap in some way.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement