Home > Backend Development > PHP Tutorial > 这段代码如何改成C#代码?或者哪位高手来解释一上

这段代码如何改成C#代码?或者哪位高手来解释一上

WBOY
Release: 2016-06-13 13:17:40
Original
884 people have browsed it

这段代码怎么改成C#代码?或者谁来解释一下?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->function querySub(&$parent, $table, $orderBy = null, $key = 'Id'){
    $sql = "SELECT * FROM $table WHERE $key = $parent[$key]";
    if($orderBy) {
        $sql .= ' ORDER BY '.$orderBy;
    }
    $rows = query($sql);
    foreach ($rows as $i => $row) {
        foreach ($row as $field => $value) {
            if($value === null) {
                $row[$field] = '--';
            }
        }
        $rows[$i] = $row;
    }
    $parent[$table] = $rows;
}
Copy after login


------解决方案--------------------
探讨

引用:

好久没写C#了

那解释一下大致思路也可以啊。。。
我就没学过php。。

------解决方案--------------------
PHP code

#运行时,必须定义一个$parent变量
$parent = null;
#函数的参数:
#&$parent: 表字段值的数组
#$table: 查询的表名
#$orderBy: 需要排序的字段
#$key: 作为查询条件的字段名,默认为Id
function querySub(&$parent, $table, $orderBy = null, $key = 'Id'){
    #查询的sql语句
    $sql = "SELECT * FROM $table WHERE $key = $parent[$key]";
    #如果添加了排序字段
    if($orderBy) {
        #在$sql后面添加排序的sql语句
        $sql .= ' ORDER BY '.$orderBy;
    }
    #执行sql语句并将结果集返回给$rows
    $rows = query($sql);
    #对$rows做循环
    foreach ($rows as $i => $row) {
        #对$rows的子数组做循环
        foreach ($row as $field => $value) {
            #如果子数组中存在空值
            if($value === null) {
                #将空值替换成"--"
                $row[$field] = '--';
            }
        }
        #重组数组
        $rows[$i] = $row;
    }
    #将重组后的数组存入$parent数组,并以表名作为其键值
    $parent[$table] = $rows;
} <div class="clear">
                 
              
              
        
            </div>
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