Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search data in multidimensional array using range values

Tags:

arrays

php

I have a multidimensional array in php.

Now I want to search for data using range values, like i want to get name of business who have business_point > 0.0 and business_point < 2.0.

I know how to search for values in array ,but i'am not able to figure how to go about searching using range, is that even possible?

So for normal searching I am using this code:

function search_array_data($options, $key, $check)
{
  $results = array();
$i = 0;
foreach ($options as $itemKey => $itemValue) {
if (in_array($itemValue[$key],$check)) {
$results[]=$itemValue;

    }  
   $i++;
}
 return $results;
}

This is my array of data:

Array
(
[0] => Array
    (
        [Business_name] => 1847(Jumeirah)
        [Business_id] => 1422
        [business_point] => 1.5
    )

[1] => Array
    (
        [Business_name] => 1847 Mens Salon(Trade Centre)
        [Business_id] => 42
        [business_point] => 1.5
    )

[2] => Array
    (
        [Business_name] => 1847 Mens Salon(Mirdif)
        [Business_id] => 1565
        [business_point] => 1.5
    )

[3] => Array
    (
        [Business_name] => 1847 Mens Salon(City  Walk)
        [Business_id] => 494
        [business_point] => 2.5
    )

[4] => Array
    (
        [Business_name] => 1847 Mens Salon(Dubai Marina)
        [Business_id] => 44
        [business_point] => 3.5
    )

[5] => Array
    (
        [Business_name] => 21 Ladies Saloon(Karama)
        [Business_id] => 1394
        [business_point] => 3.0
    )

[6] => Array
    (
        [Business_name] => 515 Medspa Center(Jumeirah)
        [Business_id] => 2125
        [business_point] => 1.5
    )
)
like image 932
Ravi Kant Singh Avatar asked Nov 26 '25 16:11

Ravi Kant Singh


1 Answers

You can use array_map function as

$result = array_filter(array_map('vas',$ararr));
function vas($t){
    if($t['business_point'] > 0 && $t['business_point'] < 2.0){
        return $t;           
    }
}

You can check it over here

like image 189
Narendrasingh Sisodia Avatar answered Nov 29 '25 04:11

Narendrasingh Sisodia



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!