php 递归函数用法示例
内容摘要
这篇文章主要为大家详细介绍了php 递归函数用法示例,具有一定的参考价值,可以用来参考一下。
下面为各位大家介绍一下php递归函数 ,对此感兴趣的朋友,看看idc笔记做的技术笔记
下面为各位大家介绍一下php递归函数 ,对此感兴趣的朋友,看看idc笔记做的技术笔记
文章正文
这篇文章主要为大家详细介绍了php 递归函数用法示例,具有一定的参考价值,可以用来参考一下。
下面为各位大家介绍一下php递归函数 ,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <code class = "php" > /** * 递归函数 * * @param * @arrange (www.idcnote.com) **/ function get_scat_url( $temp_catid ) { static $url ; global $site_id =5; if ( $temp_catid != 0) { $temp_sql =db_query( "select sm_cat_id, sm_cat_pcat_id, sm_cat_url, sm_cat_parentid from sitemap_category where sm_cat_id ='" . $temp_catid . "' and sm_domain_id ='" . $site_id . "'" ); if (db_num_rows( $temp_sql ) > 0) { $rec_set = db_fetch_array( $temp_sql ); $url = $rec_set [ 'sm_cat_url' ]. " : " . $url ; $temp_catid = $rec_set [ 'sm_cat_parentid' ]; get_scat_url( $temp_catid ); } } //first if statement return $url ; } //incorrect recursive call in php program function get_scat_url( $temp_catid ){ //global $url; $site_id =5; while ( $temp_catid != 0) { $temp_sql =db_query( "select sm_cat_id, sm_cat_pcat_id, sm_cat_url, sm_cat_parentid from sitemap_category where sm_cat_id ='" . $temp_catid . "' and sm_domain_id ='" . $site_id . "'" ); if (db_num_rows( $temp_sql ) > 0){ $rec_set = db_fetch_array( $temp_sql ); $url = $rec_set [ 'sm_cat_url' ]. " : " . $url ; $temp_catid = $rec_set [ 'sm_cat_parentid' ]; get_scat_url( $temp_catid ); } } //while ends here... return $url ; } /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
注:关于php 递归函数用法示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释