How can I write this if condition in switch method?
if( $k != \'pg_id\' && $k != \'pg_tag\' && $k != \'pg_user\' )
{
A switch condition is likely to be faster (jump table) and a bit easier to read. You can skip the break; if the result of the condition is the same and an improved syntax is to use curly braces inside each condition:
switch ($k)
{
case 'pg_id':
case 'pg_tag':
case 'pg_user': {
break;
}
default: {
$result = $connection->run_query($sql,array(...));
}
}