PHP Interview Questions
There is given PHP interview questions and answers that have been asked in many companies. Let's see the list of top PHP interview questions.
What are the uses of explode() and implode() functions?
explode() function is used to split a string into an array and implode() function is used to make a string by combining the array elements.
.$text="I like programming";print_r (explode(" ",$text));$strarr=array('Pen','Pencil','Eraser');echoimplode(" ",$strarr);
How many data types are there in PHP?
PHP data types are used to hold different types of data or values. There are 8 primitive data types which are further categorized in 3 types:
- Scalar types
- Compound types
- Special types
How can you declare the array in PHP?
You can declare three types of arrays in PHP. They are numeric, associative and multidimensional arrays.
.//Numeric Array$computer=array("Dell","Lenavo","HP");//Associative Array$color=array("Sithi"=>"Red","Amit"=>"Blue","Mahek"=>"Green");//Multidimensional Array$courses=array(array("PHP",50),array("JQuery",15),array("AngularJS",20) );
Explain Cookies? How to create cookies in PHP?
Cookies store data about a user on the browser. It is used to identify a user and is embedded on the user’s computer when they request a particular page. We can create cookies in PHP using the setcookie() function:
setcookie(name, value, expire, path, domain, secure, httponly);
here name is mandatory, and all other parameters are optional.
Example,
.setcookie(“instrument_selected”, “guitar”)
What is the difference between $message and $$message?
$message stores variable data while $$message is used to store variable of variables. $message stores fixed data whereas the data stored in $$message may be changed dynamically.
Ex : <?php $x = “blog”; $$x = 400; echo $x.“<br/>”; echo $$x.“<br/>”; echo $abc; ?>Output :
blog 400 400.
Explain the difference between require and include?
Both require and include are constructs and can be called without parentheses: include myfile.php However, if the file that is to be included is not found, include will issue a warning, and the script will continue to run. Require will give a fatal error, and the script will stop then and there. If a file is critical to the script, then require should be used, else it can be used..
Who do we know as the father of PHP?
Rasmus Lerdorf who created the language in 1994..
How a variable is declared in PHP?
A PHP variable is the name of the memory location that holds data. It is temporary storage.
$variableName=value;.
Explain the various PHP array functions?
There are many array functions, all of which are part of the PHP core:
| Array Functions | Description |
| array() | creates an array. |
| array_diff() | compares arrays and returns the differences in the values. |
| array_keys() | returns all the keys of the array. |
| array_reverse() | reverses an array. |
| array_search() | searches a value and returns the corresponding key. |
| array_slice() | returns the specific parts of the array. |
| array_sum() | sums all the values of an array. |
| count() | the number of elements of an array. |
What is “print” in PHP?
PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.
.
- int print ( string $arg)