Php 在函数中添加参数
我有两个功能一起工作。但我不能在第二个上添加参数,我不明白它是如何工作的 第一功能Php 在函数中添加参数,php,Php,我有两个功能一起工作。但我不能在第二个上添加参数,我不明白它是如何工作的 第一功能 if(!function_exists('pixiehuge_select_all')) { function pixiehuge_select_all($table, $where = null, $order = null, $limit = null, $andwhere = null, $noteq = false, $or = false) { global $wpdb;
if(!function_exists('pixiehuge_select_all')) {
function pixiehuge_select_all($table, $where = null, $order = null, $limit = null, $andwhere = null, $noteq = false, $or = false) {
global $wpdb;
$q = "SELECT * FROM `{$table}`";
$signWhere = ($or) ? 'OR' : 'AND';
// Select where
if(empty($noteq)) {
if(!empty($where)) {
$q .= " WHERE `" . esc_sql($where[0]) . "`='" . esc_sql($where[1]) . "'";
}
if(!empty($where) && !empty($andwhere)) {
$q .= " " . esc_sql($signWhere) . " `" . esc_sql($where[0]) . "`='" . esc_sql($where[1]) . "'";
}
} else {
if(!empty($where)) {
$q .= " WHERE `" . esc_sql($where[0]) . "`!='" . esc_sql($where[1]) . "'";
}
if(!empty($where) && !empty($andwhere)) {
$q .= " " . esc_sql($signWhere) . " `" . esc_sql($where[0]) . "`!='" . esc_sql($where[1]) . "'";
}
}
if(!empty($order)) {
$q .= " ORDER BY `" . esc_sql($order[0]) . "` " . esc_sql($order[1]);
}
if(!empty($limit)) {
$q .= " LIMIT 0, {$limit}";
}
// Check if plugin exists
if(!function_exists('huge_app')) {
return false;
}
$result = $wpdb->get_results($q, ARRAY_A);
return $result;
}
}
第二个函数我正在尝试编辑的函数
if(!function_exists('pixiehuge_streams')) {
function pixiehuge_streams($id = false, $streamCat = false, $slug = false) {
global $tables;
// Get Stream(s)
if($id) {
$streams = pixiehuge_select_all($tables['streams'], ['id', esc_sql($id)]);
} elseif($streamCat) {
$streams = pixiehuge_select_all($tables['streams'], ['category', esc_sql($streamCat)]);
} elseif($slug) {
$streams = pixiehuge_select_all($tables['streams'], ['slug', esc_sql($slug)]);
} else {
$streams = pixiehuge_select_all( $tables['streams'] );
}
return $streams;
}
}
我试图获取的内容$streams=“按id描述从流顺序选择*限制4”代码>(但如果我这样做,我会得到错误500)
因此,我如何通过在第二个函数中的pixiehuge\u select\u all()
中添加参数来重写$streams
,以获得id desc和limit 4的顺序?只需查看函数参数并完成它
$streams = pixiehuge_select_all($tables['streams'], [], ['id','DESC'] ,4);
那太容易了。。。它就像一个符咒,谢谢:)