Skip to content

Instantly share code, notes, and snippets.

@nelsonsar
Last active December 29, 2015 02:49
Show Gist options
  • Save nelsonsar/7603235 to your computer and use it in GitHub Desktop.
Save nelsonsar/7603235 to your computer and use it in GitHub Desktop.
Rubão, tá aí!
<?php
$where = array(
"productcategory" => array(
"id" => 410,
"productcategorytranslation" => array(
0 => array(
"translation" => "Fahrräder (Profakt)",
"id" => 952106
)
)
);
$string = "productcategory.productcategorytranslation.translation";
$keyToFind = end(explode('.', $string));
function find($keyToFind, array $where) {
foreach ($where as $k => $v) {
if ($k == $keyToFind) {
if (is_array($v)) {
return current($v);
}
return $v;
}
if (is_array($v)) {
return find($keyToFind, $v);
}
}
}
find($keyToFind, $where);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment