PHP Interview Questions
This page contains PHP interview questions and answers.
There are three types of array in PHP.
Click here to learn more about arrays in PHP.
In the following code we have an index array having 5 elements.
$arr = ['a', 'b', 'c', 'd', 'e'];
We can create the same array using array()
function.
$arr = array('a', 'b', 'c', 'd', 'e');
In the following example we have an associative array $assocArr
and we are using foreach
loop to print its content.
$assocArr = array(
'name' => 'Yusuf Shakeel',
'points' => 9.1,
'status' => 'ACTIVE'
);
foreach($assocArr as $key => $value) {
echo "<p>{$key}: {$value}</p>";
}
T_PAAMAYIM_NEKUDOTAYIM is a scope resolution operator represented by double colon ::
.
In the following code we are using the scope operator.
class MyMathClass {
const PI = 3.14;
}
echo MyMathClass::PI;
Paamayim Nekudotayim is in Hebrew and means double colon.
Session data is generally saved in file on server inside temporary temp directory.
PHP creates a unique session id and saves the file on the server and shares the session id with the client by creating a cookie in the user browser.
By default PHP session is named PHPSESSID.
Each time a client connects with the server it sends the session id with the request. The server then checks the session id and verifies the existence of the session on the server.
By default, session exists for 1440 seconds (24 minutes) on the server.
But this value can be modified in the php.ini file by changing the session.gc_maxlifetime
directive.
To get and set the current session path in PHP we have to use the session_save_path
function.
The following PHP code will print the current session path.
echo session_save_path();
The following PHP code will set the current session path.
session_save_path('/var/local/temp/session');
Following are the list of 9 primitive data types in PHP.
For this we have to set the max_execution_time
directive in the php.ini file.
In the following example we have set the max execution time to 600 seconds.
ini_set('max_execution_time', 600);
NO. Multiple inheritance is not supported by PHP.
We can only extends
one class. But we can try implementing multiple interface.
ADVERTISEMENT