摘要:
最近被一个B2B的大型购物平台给整的七晕八素的。都没怎么更新博客里面的文章了。里面的... 最近被一个B2B的大型购物平台给整的七晕八素的。都没怎么更新博客里面的文章了。里面的功能需要开发的很多很多。也许够我忙活好一阵子的了。最近整理出刚在用的父级产销商的对象分类。觉得这个api借口挺有价值值得一晒的。给各位开发界的朋友看一看,相互转发。避免再次入坑。
/**
* 通过指定ID找出他的所有父级分类
* @param array $tree
* @param string $son_item
* @param string $parent_item
* @param int $son_id
* @param array $showKey
* @param boolean $showall
* @return array
*/
function get_parent($tree,$son_item,$parent_item,$son_id,$showKey = '',$showall = false){
if(!is_array($tree) || empty($tree)){
return array();
}
if(is_string($showKey) && !empty($showKey)){
$showKey = array($showKey);
foreach ($tree as $row) {
if($row[$son_item] == $son_id){
if(!empty($showKey) && is_array($showKey) && count($showKey) >1){
foreach ($shwoKey as $s) {
if(in_array($s,array_keys($row))){
$r[$s] = $row[$s];
}
$this->_result[] = $r;
}elseif(!empty($showKey) && is_array($showKey) && count($showKey) == 1){
$this->_result[] = $row[$showKey[0]];
}else{
$this->_result[] = $row;
}
if($showall){
array_filter($this->get_parent($tree,$son_item,$parent_item,$row[$parent_item],$showKey,$showall));
}
}
}
}
}
return arr_reverse($this->_result);
}

