PHP

Interview Questions on PHP

51. What type of inheritance php supports?

PHP supports only single inheritance, where, only one class can be derived from single parent class.

52. What is the difference b/w explode and split?

split() - Split string into array based on  regular expression.
explode() - Split a string based on string

53. What is the use of <?= ?>

To print php variable into  HTML.

54. How to get the session id?

Use session_id() function.
Ex :-   $current_id=session_id();

55. How to get website url in php?

Use  $_SERVER['SERVER_NAME'];

56. How to get date in php?

Use getdate();
Ex :-
<?php
    print_r(getdate());
?>

57. How to check a empty variable?

Use empty ($var );
Ex:-
<?php
$var = 0;
// Evaluates to true because $var is empty
if (empty($var)) {
    echo '$var is either 0, empty, or not set at all';
}
?>

58. How to trim the variable?

Use trim($var);
Ex :- 
<?php
$test=”  hello world    “;
trim($test);
?>

59. How to use ternary operator?

Syntax:- expression1?expression2:expression3;
Ex :- if($a <= 3) ? echo “a is less than or equal to 3” : echo “$a is greater than 3”;

60. How to print all global variables?

print_r($GLOBALS);

www.000webhost.com