3

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
    )
)
1
  • How about doing it in two round? Commented May 8, 2015 at 6:05

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.