PHP is a backend language that we use to develop web applications and mainly for dynamic work. As I also develop websites in PHP but the thing is that when I was learning PHP I wasn’t good at theory and explaining things in PHP. But at the same time I was really good at doing practical things like logic building which is the main part of building any software. Now, when I am preparing for an interview I thought that I should share the questions that I have read for the interview. Let’s learn the fundamental of functions and PHP topics that we know or don’t know.
What is PHP stands for?
At first, when PHP language was created it was known as Personal Home Page, but it now stands for Hypertext Preprocessor.
What is a Constant in PHP?
A constant is a simple name that starts with an underscore or latter that also stores values as variables do. We can’t change the value of a constant in the entire script. We can globally access a constant in the whole script easily. And the main thing is that to define a constant we don’t use the ‘$’ sign. We define constant with a function called define()
.
define("karela", 100); //set the value
echo karela; //to get the value
What is PDO in PHP?
PDO stands for PHP Data Object. Read PDO
How to connect with Database in PHP?
When we do want to connect PHP with MySQL database then we should have three data variables. First the server name,username,and the password for connect to that particular server. It helps to connect with server database. You also can see in the code below.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
What is Session in PHP?
I see session as a person who knows our biodata on server. We can store any kind of information in session. Session ends when you ends using application.
$_SESSION['name'] = "Permjeet"; //this is how we can define a session variable
<?php
// remove all session variables
session_unset();
// destroy the session
session_destroy();
?>
We can use session in our entire script but for that you have to start session in the beginning of your script using session_start()
function.
Name and Explain 5 string functions in PHP?
- echo() we use echo() function to print output of a variable we can’t print an array with echo.
- crypt() we use crypt() function to convert a string into hash.
- explode() we use explode() function to break sting into arrays. //explode(separator,string,limit)
- str_replace() we use str_replace() function to change the string with new string or replace with new. // str_replace(find,replace,string,count)
- strpos() we use strpost() function to find a passed string position e.g strpost(‘weather’,’a’) ans:will be 2 it starts from 0 index. //stripos(string,find,start)
What is break and Continue statement in PHP?
The Continue statement goes back to the loop when loop starts then it returns the loop again on the top. But on the other hand break; statement used for when we want to get out of the loop.
Explain move_uploaded_file function?
move_uploaded_file function used to move a uploaded file to a location or destination. If this destination already exists then it does overwrite the file.
Explain unlink() function?
unlink() function is used to delete the files from destination. We do pass the filepath/filename in this function to delete any file from directories.
Explain basename() function?
basename() function helps to get the name of the file from the path.
Difference between require and include function in PHP?
One thing that I would like to clear that is both of the function used to get another PHP file in a PHP file. But there’s little difference between these to functions.
- require() function means if passed filename doesn’t exists on the destination it will stop the execution and will throw a fatal error.
- include() function also used to include the file but it doesn’t stop the execution it shows a warning and it doesn’t affect the execution of the file.
What does mysqli_num_rows() function do?
We use the mysqli_num_rows() function to count the rows we are getting in the result. It also helps to validate the condition if the result exists or not.
What is the difference between explode() and split()?
Both of the functions look and feel the same but they are not because maybe you can get the same result but the split() function takes much more execution time than explode() function. the split() function uses a pattern to split the data and on the other hand explode() function uses a string separator.
Name and Explain 5 Array functions in PHP?
Arrays are used to store multiple values in just a single variable e.g [‘first’,’second’,’third’];
- array_chunk() function splits an Array into chunks of the array. // array_chunk(array, size, preserve_key)
- array_combine() function is used to combine to an array but the condition is one array consists of “keys” and in second “values”.
- array_diff() function returns the difference between two or more arrays. //array_diff(array1,array2,array3….)
- merge_array() function merges two or more arrays in one array. // merge_array(array1,array2,…)
- array_search() function search into an array and returns the key position. // array_search(‘value’,$array);
PEAR In PHP?
PEAR is a framework and repository for reusable PHP components. It contains PHP libraries and code snippets.
How to execute SQL query and fetch the result?
For selecting the data from the database we have to use a select query. Then we have to pass a function called “mysql_query(‘select statement’). After this, we have to fetch the data with mysql_fetch_array() we have multiple functions to fetch data from the database.
$mquery = mysql_query("SELECT * FROM users where `userid` = 1");
$result = mysql_fetch_arrray($mquery);
echo $result['name'];
How to download file in PHP?
When we do upload file in php in the same way sometimes we need to download the file from storage. For download the file from storage in php we can use readfile() function that helps to download the file.
What was the old name of PHP?
Personal Home Page.
How many database PDO can work with?
If we will work with in PHP using PDO then it can connect with 10+ databases.
Conclusion
Overall we have covered some basic questions related to PHP. But I haven’t covered the any question of OOP’s here which you can see in the same category. I’ll be uploading that one also. I hope you will learn from this article. Thanks
Would you like to read about Laravel Tips.
The post PHP Interview Questions For Beginners first appeared on larachamp.com.
The post PHP Interview Questions For Beginners appeared first on larachamp.com.
Top comments (0)