【发布时间】:2014-10-02 16:13:07
【问题描述】:
这是我的数组
大批 ( [category_id] => 4 [parent_id] => 3 [名称] => 默认类别 [is_active] => 1 [位置] => 4 [等级] => 2 [孩子] => 数组 ( [0] => 数组 ( [category_id] => 122 [parent_id] => 4 [名称] => 根 [is_active] => 1 [位置] => 1 [等级] => 3 [孩子] => 数组 ( [0] => 数组 ( [类别 ID] => 123 [parent_id] => 122 [名称] => 服装 [is_active] => 1 [位置] => 1 [等级] => 4 [孩子] => 数组 ( [0] => 数组 ( [category_id] => 124 [parent_id] => 123 [名称] => 男装 [is_active] => 1 [位置] => 1 [等级] => 5 [孩子] => 数组 ( [0] => 数组 ( [类别 ID] => 125 [parent_id] => 124 [名称] => Polo 衫和 T 恤 [is_active] => 1 [位置] => 1 [等级] => 6 [孩子] => 数组 ( ) ) ) ) ) ) [1] => 数组 ( [类别 ID] => 126 [parent_id] => 122 [名称] => 时尚 [is_active] => 1 [位置] => 2 [等级] => 4 [孩子] => 数组 ( [0] => 数组 ( [类别 ID] => 127 [parent_id] => 126 [名称] => 鞋类 [is_active] => 1 [位置] => 1 [等级] => 5 [孩子] => 数组 ( [0] => 数组 ( [category_id] => 128 [parent_id] => 127 [名称] => 女性 [is_active] => 1 [位置] => 1 [等级] => 6 [孩子] => 数组 ( [0] => 数组 ( [类别 ID] => 129 [parent_id] => 128 [名称] => 公寓 [is_active] => 1 [位置] => 1 [等级] => 7 [孩子] => 数组 ( ) ) ) ) ) ) ) ) ) ) ) )和 我想做的是: 写一个函数
foo($find,$array){
//do some coding to search in the array
return $category_id;//category id of the coresponding matched name in array
}
例如:
foo("Clothing",$array); 将返回 18
foo("Men Clothing",$array) 将返回 19
等等
【问题讨论】:
标签: php arrays search tree nested