How can I tidy multiple if condition for readability?
For instance,
if( $key != 'pg_id' && $key != 'pg_tag' && $key != 'pg_user' )
This confuses me when the items in that condition grow longer.
It was used in this kind of situation below - foreach()
,
$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 = ?";
}
I was thinking using switch but I think I was wrong!