I am checking does specific value exist as key in array and I need to do following - if it exist to collect some data. Here is a situation:
$valueCode; //(it can be EV000005, EV000010, etc.)
$temp = array_key_exists_custom($valueCode,$v); //does valueCode exist in array $v
//If it exist I need to collect it is value deeper from structure
//For example, for EV000005 -> I want to get 'Thread holding'
if ($temp) {
$colValue; // after perfroming code, $colValue should have value 'Thread holding'
}
In case that I have only EV000005 in structure I will do this and get the value.
$colValue = $v[0][$valueCode][0][0][1];
But it is not solution to me because there is situation when my value will not be in $v[0], f.e. when we search EV000010 it will be in $v[1][$valueCode][0][0][1];. I have no idea what is the best way to get this value.
Array example:
Array
(
[0] => Array
(
[EV000005] => Array
(
[0] => Array
(
[0] => Array
(
[0] => EN
[1] => Thread holding
)
[1] => Array
(
[0] => nl-NL
[1] => Schroefdraadhouder
)
)
)
)
[1] => Array
(
[EV000010] => Array
(
[0] => Array
(
[0] => Array
(
[0] => EN
[1] => Desoldering iron
)
[1] => Array
(
[0] => nl-NL
[1] => Desoldeerbout
)
)
Function for search in array
function array_key_exists_custom($needle, $haystack){
$result = array_key_exists($needle, $haystack);
if ($result) {
return $result;
}
foreach ($haystack as $v) {
if (is_array($v)) {
$result = array_key_exists_custom($needle, $v);
}
if ($result) {
return $result;
}
}
return $result;
}
[0][0][1]- always the same?$res = array_key_exists_custom($key, $arr)[0][0][1];$result = array_key_exists($needle, $haystack); if ($result) { return $haystack[$needle]; }