PHP interview questions and answers for 3 year of experience

Question: Are PHP functions case sensitive?
No, functions are case in-sensitive
In built functions are are case-insensitive like print, strtolower, array_merge etc.
user defined functions are also are case-insensitive (New function created by user as per requirment).

Question: How to return call by reference value from function?
Just use &(ampersand) before the function name.
For Example.

function &showData($data){
   $data.=' New String';    
   return $data;

Question: How to check a form is submited OR Not?

    //form is submitted

Question: How to remove all leading zeros from string?

echo ltrim('00000012', '0'); //12

Question: How to find HTTP Method?


It will return GET, HEAD, POST, PUT etc

Question: How to Serializing PHP object to JSON?

$userModel = new UserModel();
echo json_encode($userModel);//serialize data

Question: How to get current URL of web page?

echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

Question: How to add N number of days in an data?

echo date('Y-m-d', strtotime("+30 days"));

Question: How to get Yesterday date?

echo date("F j, Y", time() - 60 * 60 * 24); //November 1, 2016

Question: What’s the maximum size for an int in PHP? The size of an integer is platform-dependent
Maximum value of about two billion for 32 bit system.

Question: How to remove all specific characters at the end of a string?

$string = 'Hello. * cool';
echo $string = str_replace(array('*', '.',' '), '', $string); //Remove * . and space [you can add more as you want]