Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表排除列的JSON数组_Php_Jquery_Json - Fatal编程技术网

Php 表排除列的JSON数组

Php 表排除列的JSON数组,php,jquery,json,Php,Jquery,Json,我编写了一个简单的函数,它获取我的一个数据库表并输出一个完整的JSON数组 function tableJSON ($table, $orderby) { $array = array(); $sql = Nemesis::select("*", $table, NULL, $orderby); if ($sql) { if ($sql->num_rows > 0) { while ($row = $sql->fe

我编写了一个简单的函数,它获取我的一个数据库表并输出一个完整的JSON数组

function tableJSON ($table, $orderby) {
    $array = array();
    $sql = Nemesis::select("*", $table, NULL, $orderby);
    if ($sql) {
        if ($sql->num_rows > 0) {
            while ($row = $sql->fetch_assoc()) {
                // push row values to array
                array_push($array, $row);
            }
            return json_encode($array);
        } else {
            echo 'Query returned empty';
        }
    } else {
        echo 'Query error';
    }
}
从该数组中,使用所述方法生成一个表。然后我将表格分拣机应用于表格。我的问题是,目前,该脚本输出所有行和列。例如:

[{"id":"109225488","project_name":"One on One Interview the Dean of RSM","project_bold":"Interview","project_content":"Interview with the Dean of Erasmus University Rotterdam School of Management. Interviewer: Joost Kammermans.","project_image_1":"\/images\/uploads\/projects\/109225488\/m_109225488_1.jpg","project_image_2":"","project_image_3":"","project_image_4":"","youtube_link":"http:\/\/www.youtube.com\/watch?v=9rsR3FcLAxI","published":"1","created":"2013-05-29 14:07:49","created_by":"1","last_modified":"2013-07-22 19:43:15","last_modified_by":"1"}
如何从输出被排除列的数组中排除此脚本

例如:

$excluded=array('created_by','project_image_1')

我尝试了
array\u diff
,但没有成功

$sql = Nemesis::select("*", $table, NULL, $orderby);

*
更改为只包含要输出的列的列表,这样您就不必担心后端阵列的麻烦。

我建议Devisioner给出答案,但是

function tableJSON ($table, $orderby, $excluded = array()) {
    $array = array();
    $sql = Nemesis::select("*", $table, NULL, $orderby);
    if ($sql) {
        if ($sql->num_rows > 0) {
            while ($row = $sql->fetch_assoc()) {
                $newrow = array();

                foreach($row as $col => $val)
                    if(!in_array($col, $excluded))
                        $newrow[$col] = $val;
                // push row values to array
                array_push($array, $newrow);
            }
            return json_encode($array);
        } else {
            echo 'Query returned empty';
        }
    } else {
        echo 'Query error';
    }
}

有趣的一点,但为了我自己的利益,我很好奇。在任何情况下,我都会投赞成票——只处理你需要的栏目是你最好的选择——你不必以奇怪的方式筛选数据。