Home > Backend Development > PHP Tutorial > In the specific code below, how to remove the reference parameters and use the return value instead?

In the specific code below, how to remove the reference parameters and use the return value instead?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:52:05
Original
1068 people have browsed it

The code is as follows:

<code>//返回指定的$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);
    }
} </code>
Copy after login
Copy after login

gongchengleibie is a database table with a 3-layer tree structure, as shown below
In the specific code below, how to remove the reference parameters and use the return value instead?

I want to remove the reference parameter $str and use the return value instead, but my attempt failed.
How to change it?
If it cannot be changed, what is the reason?

Thank you all for your attention or answers.
If there is incomplete information or unclear description of the problem, sorry please let me know and I will add it immediately.

Reply content:

The code is as follows:

<code>//返回指定的$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);
    }
} </code>
Copy after login
Copy after login

gongchengleibie is a database table with a 3-layer tree structure, as shown below
In the specific code below, how to remove the reference parameters and use the return value instead?

I want to remove the reference parameter $str and use the return value instead, but my attempt failed.
How to change it?
If it cannot be changed, what is the reason?

Thank you all for your attention or answers.
If there is incomplete information or unclear description of the problem, sorry please let me know and I will add it immediately.

Just change it to this, I won’t say more.

<code>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);
    }
    return $str;
} </code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template