I have a big array (10M of strings). I have to get value by key or by value many times.
To get by key, I use isset
=> O(1) => much faster.
To get by value, I use in_array
or => O(n) => more slowly, because it does a linear search though the array until it finds the value.
In PHP, Is it possible to set key with more items and do optimize search on kthis key?
For example :
$bigArray = ((0, "s0") => true,
(1, "s1") => true,
(2, "s2") => false,
....,
(1000000, "s1000000") => true);
$Test2 = get_optimize_function("s2", $bigArray); // Key = (2, "s2"), Value = false
$Test1 = get_optimize_function(1, $bigArray); // Key = (1, "s1"), Value = true