In the following specific code, how do I remove the reference parameter and use the return value instead?

Source: Internet
Author: User

The code is as follows:

//返回指定的$aid 的工程类别id和他的下级类别id//参数://  $aid 工程类别, int类型//  $conn 数据库连接//  $str,返回值,字符串类型// 返回: 字符串,类似于 "1,3,7,8,"function get_gongchengleibie($aid, &$str, $conn){    $str = "";    $query=mysql_query(" select * from gongchengleibie where pid=$aid",$conn);    while($row=mysql_fetch_array($query))    {        $str .= $row["id"].",";        get_gongchengleibie($row["id"], $str1, $conn);    

Gongchengleibie is a database table, a 3-tier tree structure, such as

I want to remove the reference parameter $str, instead of using the return value of the way, I try to fail.
How can I change it?
If it can't be changed, what causes it?

Thank you to the great God for your attention or answer.
If the information is incomplete or the problem description is unclear, sorry + request to inform, I will immediately add.

Reply content:

The code is as follows:

//返回指定的$aid 的工程类别id和他的下级类别id//参数://  $aid 工程类别, int类型//  $conn 数据库连接//  $str,返回值,字符串类型// 返回: 字符串,类似于 "1,3,7,8,"function get_gongchengleibie($aid, &$str, $conn){    $str = "";    $query=mysql_query(" select * from gongchengleibie where pid=$aid",$conn);    while($row=mysql_fetch_array($query))    {        $str .= $row["id"].",";        get_gongchengleibie($row["id"], $str1, $conn);    

Gongchengleibie is a database table, a 3-tier tree structure, such as

I want to remove the reference parameter $str, instead of using the return value of the way, I try to fail.
How can I change it?
If it can't be changed, what causes it?

Thank you to the great God for your attention or answer.
If the information is incomplete or the problem description is unclear, sorry + request to inform, I will immediately add.

Change to do so, many will not say.

function get_gongchengleibie($aid, $conn){    $str = "";    $query=mysql_query(" select * from gongchengleibie where pid=$aid",$conn);    while($row=mysql_fetch_array($query))    {        $str .= $row["id"].",";        $str .= get_gongchengleibie($row["id"], $conn);    }    
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.