TOP 25+ Core PHP Interview questions and answers for freshers 2018

TOP 25+ Core PHP Interview questions and answers for freshers 2018




In this article I am going to tell Top 25+ Common Core PHP Interview questions and answers for freshers. In Web development era PHP is a common language that helps to the fresher candidate to get the jobs easily. In PHP there are huge numbers of jobs available in the Software Market but still, for that, you need some basic knowledge to at least qualify the technical Interview.

So, here I am writing Top Common Core PHP interviews questions with their answers.

#1.What is PHP OR Can you tell me Something about PHP?

Best Answer:- PHP is a server-side scripting language commonly used for creating dynamic web applications. PHP has their Code frameworks for example like(Laravel, Zend, CodeIgniter, Symphony, CakePHP) and Content Management Systems(WordPress, Drupal, Joomla) and ECommerce Platforms for Creating websites.

#2:- What’s the Main difference between the include() and require() functions?

Best Answer:- They both include a specific file but on require the if the file can’t be included, a process will exit with a fatal error but in the same case in include statement may still pass and jump to the next step in the execution.

#3:- What’s the Main difference between unset() and unlink()

Best Answer:- unset() is used to destroy a variable whereas unlink() is used to destroy a file.

#4:- What is the difference between GET and POST?

— GET displays the submitted data as part of the URL, during POST this information is not shown as it’s encoded in the request.
— GET can handle a maximum of 2048 characters, POST has no such restrictions.
— GET allows only ASCII data, POST has no restrictions, binary data are also allowed.
— GET is used to retrieve data where POST to insert and update.

#5:How to include a file to a php page?

Best Answer:- In php We can include a file using include() or require() function with file path as its parameter.

#6: How you will declare an array in php?

you can declare an array in php like in this way

var $arr = array('Php', 'java', 'ruby');

#7:why we use in_array() function in php ?

in_array used to checks if a value exists in an array




Free Download Complete PDF with Answers




#8: What is use of count() function in php ?

count() is used to count all elements in an array or something in an object.

#9: How we can retrieve the data in the result set of MySQL using PHP?

1. mysql_fetch_row
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc

#10:-How to set cookies in PHP?

Setcookie(“New_sample”, “ram”, time()+3600);

#11: What is the use of explode() function ?

This PHP function breaks a string into an array.


$str = 'one,two,three,four';

// zero limit
print_r(explode(',',$str,0));

// positive limit
print_r(explode(',',$str,2));

// negative limit
print_r(explode(',',$str,-1));

Core PHP interviews questions with their answers

#12:- How to redirect a page in php?

The following code can be used for it, header("Location:index.php");

#13:-How you will find the length of a string?

strlen() function used to find the length of a string.

#14:- How you will stop the execution of a php script ?

In php exit() function is used to stop the execution of a page.

#15:- What is mean by an associative array?

Associative arrays are arrays that use string keys is called associative arrays.

you can create an associative array in this way

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

#16:- How to find current date and time?

The date() function provides you to retrieve the current date and time.

#17: Why we use “ksort” in php?

It is used for sort an array by key in reverse order.

#18: What is the difference between $var and $$var?

Both are the Variables, But $var is a variable with a fixed name. $$var is a variable whose name is stored in $var. For example, if $var contains “message”, $$var is the same as $message.

#19: How to delete a file from the system?

Unlink() deletes the given file from the file system.

#20: What is the main difference between explode() and split() functions?

Split function splits a string into array by regular expression while Explode splits a string into array by string.

#21: Can you write sample code for save an uploaded file in php?


if ($_FILES["file"]["error"] == 0)
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"image_upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "image_upload/" . $_FILES["file"]["name"];
}

#22: How to strip whitespace from the beginning and end of a string ?

The trim() function is used for removes whitespaces or other predefined characters from both sides of a string.

#23: How you will define a constant in php?

Using define() directive, like for example define ("MYCONSTANT",250)

#24:- How you will send email using php?

For Sending email using PHP, you can use the mail() function. mail() function accepts 5 parameters.

mail($to,$subject,$message,$headers);

#25: What are the encryption techniques in PHP

MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg);

Generally we used the MD5 function to encrypt the password.

#26: How will you generate random numbers using PHP?

The rand() function in php is used for generate a random number. This function can generate numbers with-in a given range.

#27: What to use $_PHP_SELF variable?

$_PHP_SELF variable is used for the PHP script name and suppose when you click “submit” button then same PHP script will be called inside your page.

#28: How will you create Database connection using mysqli

$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

#29: What’s the main difference between echo, print, and print_r in PHP?

echo

— Outputs one or more strings separated by commas
— No return value

e.g. echo “String 1”, “String 2”

print

— Outputs only a single string
— Returns 1, so it can be used in an expression

e.g. print “Hello”

or, if ($expr && print “foo”)

print_r()

— It Accepts strings and other types including arrays and objects, formatting them to be readable
Useful when debugging.
— for example you can directly pass the array to print_r() function to see the values.

Krishna Gupta

Krishna Ballabh Gupta is a Gold Medalist Full Stack Developer & Algorithm Designer and Founder of TechnologyShouters. He generally Blogs about Python, JavaScript, jQuery, AngularJS, Database, PHP, AJAX and something that interesting.

Related Posts

Create Account



Log In Your Account



1Subscribe to Our Live Updates.