note 121247 deleted from function.array-search by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 20:45:10 +0000 |
| Subject: | note 121247 deleted from function.array-search by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217959@lists.php.net to get a copy of this message | ||
Note Submitter: mohamedn085 at gmail dot com
----
Mohamed Nabil
hallo every body This function matches two arrays like
search an array like another or not array_match which can match
function array_match($arr1,$arr2,$highlevel=false)
{
$keys1=array_keys($arr1);
$keys2=array_keys($arr2);
$values1=array_values($arr1);
$values2=array_values($arr2);
if ($highlevel)
{
if ($keys1 === $keys2 && $values1 === $values2)
{
return true;
}
return false;
}
if ($keys1 == $keys2 && $values1 == $values2)
{
return true;
}
return false;
}
var_dump(array_match(['id'=>'1','username'=>'2'],['id'=>'1','username'=>2]));
//Output:true
var_dump(array_match(['id'=>'1','username'=>'2'],['id'=>'1','username'=>2],true));
//Output:false