Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check value within range or not php

I want to check value with in range or not suppose if I have range D1 to D40 and if I enter D20 then it returns value with in range.

I check several solution but this are for only integer not for both string and integer.

EDIT

Range will be dynamic like AA20 to AA30 or like AC10D to AC30D

like image 932
Keyur Shah Avatar asked Nov 26 '25 16:11

Keyur Shah


1 Answers

You can write something simpler like this...

$arr = range(1,40); //<--- Creating a range of 1 to 40 elements..
array_walk($arr,function (&$v){ $v = 'D'.$v;}); //<--- Concatenating D to all the elements..
echo in_array('D20',$arr) ? 'Found' : 'Not Found'; //<-- The search part.

Demonstration

like image 97
Shankar Narayana Damodaran Avatar answered Nov 28 '25 15:11

Shankar Narayana Damodaran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!