1
I have two arrays:
$Keys
Array
(
[0] => Array
(
[0] => {3}
[1] => {1}
[2] => {2}
[3] => {0}
[4] => {4}
[5] => {5}
)
);
$properties
Array
(
[0] => Array
(
[0] => var::terms::
[1] => var::create_terms >> 1::
[2] => const::EXAMPLE123::
[3] => var::create_terms>>0::
[4] => text::serio mesmo::
[5] => ::ENTER::
)
... // outras keys que não estão relacionadas
)
And I would like to know which way is the most correct and recommended in terms of performance and semantics, check the existence of array 1 values (without {}
square brackets) in array 2 Keys (I have two examples)
$keys[1] = array_map(function ($keys) {
return str_replace(['{', '}'], null, $keys);
}, $keys[0]);
sort($keys[1]);
if (in_array($keys[1], [array_keys($properties[0])], false)) {...} else {...}
OR
$keys[1] = array_map(function ($keys) {
return str_replace(['{', '}'], null, $keys);
}, $keys[0]);
foreach ($keys[1] as $key) {
if (array_key_exists($key, $properties[0])) {...} else {...}
}
If you keep the same Keys, you can turn it into an array with
array_keys()
and then usearray_compare()
orarray_intersect()
to see if there are differences between one and the other.– William Aparecido Brandino
I think it would consume more processes using these functions, @William Aparecido Brandino.
– Daniel Omine
I agree, @Danielomine, there are several ways to check if one exists in another. This is a.
– William Aparecido Brandino