php无限分类 递归

    xiaoxiao2022-06-23  19

    foreach( array_keys( $list ) as $key ) { if( $list[$key]['fid'] == 0 ) { continue; } if( putChild( $list , $list[$key] ) ) { unset( $list[$key] ); } } function putChild( &$list , $tree ) { if( empty( $list ) ) { return false; } foreach( $list as $key => $val ) { if( $tree['fid'] == $val['id'] && $tree['id'] != $tree['fid'] ) { $list[$key]['child'][] = $tree; return true; } if( isset( $val['child'] ) && is_array( $val['child'] ) && !empty( $val['child'] ) ) { if( putChild( $list[$key]['child'] , $tree ) ) { return true; } } } return false; } echo "<pre>"; print_r( $list );
    转载请注明原文地址: https://ju.6miu.com/read-1123127.html

    最新回复(0)