1

I have this code that is looking for $array2 in $array1.

The issue that I have is that I need to lowercase both arrays so the in_array matching works and this code operates as expected but $array1 is greater than 20k objects -- is there anyway to do the lowercase without losing the array structure and looping?

$array1 = array(code => 200, status => success,
        array(
        'email' => '[email protected]',
        'status' => 'Pending'
        ),
       array(
        'email' => '[email protected]',
        'status' => 'Approved: Printed & Cleared'
        ),
      array(
        'email' => '[email protected]',
        'status' => 'Approved'
        ),
      array(
        'email' => '[email protected]',
        'status' => 'Approved: Printed & Cleared'
        ),
        );

$yourArray = array();
$array = array();
foreach ($array1 as &$array){

$yourArray[] = array_map('strtolower', $array);

}

echo "<pre>"; print_r($yourArray);

$array2 = array(
        'email' => '[email protected]',
        'status' => 'Pending'
        );   

$yourArray2 = array_map('strtolower', $array2);         

if(in_array($yourArray2 , $yourArray)) {
echo "match";
} else {
echo "no match";
}

echo "<pre>"; print_r($yourArray2);
1
  • note that array_walk and array_walk_recursive can both do this Commented Apr 10, 2017 at 16:16

1 Answer 1

0

You can always use preg_grep() function:

preg_grep("/ONe/i", $yourArray2);
Sign up to request clarification or add additional context in comments.

3 Comments

Note: This can be resource-intensive at 20k elements.
More resource-intensive than loop with 20k iterations? :) I don't think so
Actually, it could be, especially in memory consumption. looping vs grep

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.