Created
April 19, 2011 14:18
-
-
Save akost/927991 to your computer and use it in GitHub Desktop.
How to find parent of element?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Дано $foo и массив. Значения элементов -- уникальны. | |
* Как найти родителей элемента? | |
* Т.е., если $foo = 22, надо найти "MSK" и "Street_1" | |
* Или как найти индекс элемента: $cities["MSK"]["Street_2"][1]? | |
* Элемент не равен $foo, их связь вычисляется некоторой функцией | |
* | |
* Или, хотя бы, надо проверить, что элемент building_22 находится в массиве $cities["MSK"] | |
* | |
*/ | |
$foo = 22; | |
$cities = array( | |
"MSK" => array( | |
"Street 1" => array( | |
"building_11", | |
"building_12", | |
"building_13", | |
), | |
"Street 2" => array( | |
"building_21", | |
"building_22", | |
"building_23", | |
) | |
), | |
"SPB" => array( | |
"Street 1" => array( | |
"building_111", | |
"building_112", | |
"building_113", | |
), | |
"Street 2" => array( | |
"building_121", | |
"building_122", | |
"building_133", | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment