Recursive match for array keys based of checking through a array of variables in a mustache template with it's includes
<?php | |
class ArrUtils | |
{ | |
/** | |
* @param $searchKey | |
* @param $dataArray | |
* @return boolean | |
*/ | |
protected function isKeyInArray($searchKey, $dataArray) | |
{ | |
// Ignore endif statements | |
if ($searchKey[0] === '/') { | |
return true; | |
} | |
// Include if/else blocks | |
if ($searchKey[0] === '#' || $searchKey[0] === '^') { | |
$searchKey = substr($searchKey, 2, strlen($searchKey) - 2); | |
} | |
if (array_key_exists($searchKey, $dataArray)) { | |
return true; | |
} | |
foreach ($dataArray as $element) { | |
if (is_array($element)) { | |
if ($this->isKeyInArray($searchKey, $element)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment