Skip to content

Truelancer Blog

  • Post Project
  • Find Freelancers
  • Find Projects
  • Signup

Top 10 PHP Interview Questions & Answers

September 14, 2016 by chittaranjan deo

As a candidate for PHP (Web development) you would definitely like to know the best possible questions you might face in your next PHP Interview. Thought the questions change from one interviewer to another, we would like to put together a set of questions considering that it is expected from you to know the correct answers to these questions.

List of PHP Freelancers

Question 1

What is PHP? Is it licensed?

Answer: PHP stands for hypertext pre-processor, which is an open source scripting language. Today it is most famous scripting language for developing web sites. It is used as server side scripting language as well as general purpose programming language. PHP code is executed on the server.

*Tip: It is good to mention about use of language on client side or server side

Question 2

Which are the famous PHP frameworks?

Answer: There are many PHP frameworks. Some of the famous ones are:

Laravel, Phalcon, Symfony 2, Yii Framework, Codeigniter, CakePHP, Zend, Zoop, etc.

*Tip:  You can add which ones you are using at present to the answer of this question

Question 3

How will you write a small function in PHP to get remote IP address?

Answer:

    function getRemoteIP() {

        $ip = $_SERVER[‘REMOTE_ADDR’];

    }

*Tip: Be hands-on for quickly writing some snippets in the language you are being interviewed

Question 4

Which data types are supported by PHP?

Answer: PHP supports – String, Boolean, Integer, Float, Object, Array, NULL and Resource

*Tip: PHP data types and may be some examples are important for data handling knowledge

Must Read  Top 10 SQL Interview Questions & Answers

Question 5

What will be the use and output of the below code snippet?

<?php
function file_size($url){
$size = filesize($url);
if($size >= 1073741824){
$fileSize = round($size/1024/1024/1024,1) . ‘GB’;
}elseif($size >= 1048576){
$fileSize = round($size/1024/1024,1) . ‘MB’;
}elseif($size >= 1024){
$fileSize = round($size/1024,1) . ‘KB’;
}else{
$fileSize = $size . ‘ bytes’;
}
return $fileSize;
}
echo file_size(‘/myfile/image.jpg’);
?>

Answer: The above code will display the file size along with GB, MB, KB or bytes

*Tip: You can expect a reverse question also like the above one, where a code snippet can be provided to you and you are expected to tell the outcome

Question 6

What is an Array and what are the types of arrays in PHP?

Answer: An array is a data structure that stores one or more similar type of values in a single value. In PHP, there are three types of arrays:

Indexed arrays – Arrays with a numeric index

Associative arrays – Arrays with named keys

Multidimensional arrays – Arrays containing one or more arrays

*Tip: Don’t miss the Array part in any programming language which will always have at least one of the questions

Question 7

IF a single line to be read from a given text file, how will you write a PHP function to do this task?

Answer:

<?php

$myfile = fopen(“webexample.txt”, “r”) or die(“Unable to open file!”);

echo fgets($myfile);

fclose($myfile);

?>

*Tip: Questions about writing simple functions are common in technical interviews of experienced people.

Question 8

What is PDO? Can you give an example of how to connect to the DB using PDO?

Answer: PDO is PHP Data Object which can be used to access data from any DB from PHP

try {

   $conn = new PDO(“mysql:host=$servername;dbname=myDB”, $username, $password);

   // set the PDO error mode to exception

Must Read  Top 10 Java Interview Questions & Answers

   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

   echo “Connected successfully”;

   }

*Tip: Connecting to DB is most important part of your programming as you will not be able to do half of the things without connecting to DB. Also it is not expected to write entire program while giving any example but you can write only the required code

Question 9

What is a CMS and which are some of the famous PHP based CMS?

Answer:  CMS or a Content Management System is an Application which allows to manage, organise, create, edit and publish a website easily.

Most famous CMS today are mainly based on PHP and some of them are WordPress, Joomla, Drupal, AdaptCMS, CMS made simple, Exponent CMS, PHP fusion, PHP Nuke, etc.

*Tip: CMS is one of the key part in any web development now and knowledge about a few CMS systems is going to make your life easy

Question 10

What do these functions do in PHP?

max(), min(), floor(), data_diff(), time()

Answer:

max() returns the highest value in an array

min() returns lowest value in an array

floor() rounds a number down to the nearest integer

date_diff()returns the difference between two dates

time() returns the current time

*Tip: Readymade functions are most handy tools and knowing some of the common used functions by heart is always good to speed up your programming.

We hope you have got the gist of important questions which can help you prepare for your interview

All the Best!

Post navigation

Previous Post:

Top 10 HTML5 Interview Questions & Answers

Next Post:

Top 10 Java Interview Questions & Answers

Become a Freelancer

Popular Posts

  • Workflow between Freelancer & Client. Workstream Step by Step Guide
  • How to withdraw money from your Truelancer Account
  • Introducing Instant Hire – Re-Hiring Made Easy!
  • Payment withdrawal options on Truelancer
  • Send a Perfect Proposal for Projects on Truelancer

Recent Posts: Truelancer Blog

List of Freelance Sites to Start Freelancing

List of Freelance Sites to Start Freelancing

Freelancing Success: Graphic Designer with 5 Star Ratings!!

Freelancing Success: Graphic Designer with 5 Star Ratings!!

Freelancing Success: Meet Aditya Web and Android Developer from Bangalore

Freelancing Success: Meet Aditya Web and Android Developer from Bangalore

Freelancing Success: Meet Vishal Shah who earned $10000 in just 90 days!

Freelancing Success: Meet Vishal Shah who earned $10000 in just 90 days!

Prince from Kenya-Amazing Content Writer, who always get 5 Star Ratings

Prince from Kenya-Amazing Content Writer, who always get 5 Star Ratings

Categories

  • Academy
  • Achitect
  • Affiliate Marketing
  • Angel Investors
  • Announcements
  • Article Writing
  • Artificial Intelligence
  • Blogging
  • Book Release
  • ChatGPT
  • Content Marketing
  • Coworking Spaces
  • Crowdsourcing
  • Digital marketing
  • Digital Superstars
  • E-commerce
  • Email Marketing
  • Entrepreneurs
  • Entrepreneurship & Startup
  • Events
  • Featured Freelancers
  • Featured Stories
  • Freelance Jobs
  • Freelancer
  • Freelancer Report
  • Freelancer Tips
  • Freelancing
  • Graphic Design
  • Grok AI
  • Infographics
  • Interior Designer
  • Interview Questions
  • IT & Programming
  • Make Money Online
  • Mobile App Development
  • News
  • Online Jobs
  • Outsourcing
  • Payments
  • Payoneer & Truelancer
  • Pro Membership
  • Product Updae
  • Product Updates
  • Programmers
  • Project Management
  • Remote Team
  • Remote Work
  • Research & Analytics
  • SEO & SEM
  • SEO and Online Media
  • Small Business
  • Social Media & Marketing
  • Software Development
  • Startups
  • Startups
  • Superlancer
  • Translation
  • Trending Services
  • Truelancer General
  • Truelancer Offers
  • Tutorials
  • Uncategorized
  • Video Editing
  • Virtual Assistants
  • Web Development
  • Website Designing
  • Writing and Content
  • Yoga
  • Become a Freelancer
© 2025 Truelancer Blog | WordPress Theme by Superbthemes