我该怎么写这个if condition
in switch
method?
if( $k != 'pg_id' && $k != 'pg_tag' && $k != 'pg_user' )
{
$result = $connection->run_query($sql,array(...));
}
to...?
switch($k)
{
case 'pg_id': false;
case 'pg_tag': false;
case 'pg_user': false;
default:
$result = $connection->run_query($sql,array(...));
}
EDIT:
抱歉,我想我之前没有说清楚,下面是我想如何使用它,
$editable_fields = array(
'pg_id',
'pg_url',
'pg_title',
'pg_subtitle',
'pg_description',
'pg_introduction',
'pg_content_1',
'pg_content_2',
'pg_content_3',
'pg_content_4',
'pg_backdate',
'pg_highlight',
'pg_hide',
'pg_cat_id',
'ps_cat_id',
'parent_id',
'tmp_id',
'usr_id'
);
$sql_pattern = array();
foreach( $editable_fields as $key )
{
if( $key != 'pg_id' && $key != 'pg_tag' && $key != 'pg_user' ) $sql_pattern[] = "$key = ?";
}
正如你所看到的,我在那里重复了这个条件 -
if( $key != 'pg_id' && $key != 'pg_tag' && $key != 'pg_user' )
并且在某个时候它可能会变长。