If you’re looking for a job in tech, PHP isn’t a bad place to start. PHP powers platforms like Facebook, WordPress, Yahoo, and Wikipedia. Since it’s one of the most commonly used programming languages, companies regularly need to hire PHP developers, from entry-level to advanced.
If you’re new to PHP and preparing to interview for a job that will require you to know how to use it, here are seven questions that you might be asked during your interview — and some possible answers to help you prep.
1. What is PHP? And how does it work?
You may not directly be asked this one, but it’s something you should know if you’ll be expected to use PHP in the role you’re interviewing for. PHP (or PHP: Hypertext Preprocessor) is a general-purpose scripting language popular for developing dynamic web pages. Developers primarily program with PHP to work on the server-side of web programs. However, command-line scripting or writing desktop applications is also possible.
People use PHP to create the back-end of web-based applications. PHP mode in HTML documents allows the embedding of PHP script to perform tasks like collecting form data, generating dynamic page content, and working with cookies.
Even if you’re not asked to explain PHP, you can show your knowledge of PHP by explaining what you’ve personally used PHP for. Have you been involved in building a PHP-driven online community? Tell your interviewer about this. What about building an e-commerce website? Explain how you used PHP for that.
2. What types of functions are commonly used in PHP?
PHP allows for both user-defined functions, as well as internal (built-in) functions. Popular examples of a built-in function are ‘echo’ and ‘print,’ which are commonly used. Other internal functions include image, string, and variable functions.
User-defined functions are simply functions that are not built-in. They are written by the user. Examples of such functions are conditional functions, functions within functions, and recursive functions. Below is an example of pseudocode that defines a user’s function:
<?php
function codecademy($arg_1, $arg_2) {
$user_defined = $arg_1 + $arg_2;
echo “Example function.n”;
return $user_defined;
}
?>
3. Have you used PEAR? If so, what is it?
Assuming you’ve used PEAR, here’s how you could answer this question:
PEAR stands for PHP Extension and Application Repository and is a PHP framework and distribution system for reusable PHP components. It’s a leading promoter of PHP syntax standards and is definitely good to know for any PHP developer.
Even if you haven’t used PEAR, you can still answer this question with the above. And just say you haven’t used PEAR yet, but you’re looking forward to using it on an upcoming project. Remember: You’re not expected to know everything during an interview, and it’s okay to say when you don’t know something.
4. What are the different types of variables present in PHP?
There are eight different types of PHP variables. They are Integers, Doubles, Booleans, NULL, Arrays, Strings, Resources, and Objects.
Note: If you’re asked this question, the interviewer probably doesn’t expect you to explain all eight variables. They might not even expect you to name all eight, but if you can, go for it. They’re probably looking for you to explain a few of them and how you would use them. Here are three options:
- Arrays: An array is a variable that can hold more than one value. Example: $colors = array(“red”, “yellow”, “blue”);
- Strings: A string is a sequence of characters. Ex: “Hello Codecademy!”
- NULL: NULL is used when a variable does not have a value. When no value is assigned to a variable, you can assign it with NULL.
5. What are the three types of Arrays in PHP? And what are they used for?
Indexed or Numeric Array: One type of array is an Indexed or Numeric Array, in which a list of ordered, stored data composites a data structure. Each element in an array is known as the index location. They are used to store, access, and manipulate data.
Associative Array: In PHP, associative arrays are map-like data structures where meaningful keys are assigned to values. Let’s look at an example (below), where the key “num” points to value “2”, and the key “material” points to the value “egg.”
$chicken = [“num” => 2, “material” => “egg”];
Multidimensional Array: The third type of array is the multidimensional array, which can contain an array at each index instead of elements. These types of arrays are used for organizing data, as well as simply storing more information
6. What is your experience with using loops in PHP?
This is a question where you should weave in details about your own work while also answering the original question. But each type of loop is used for a different purpose, so it’s good to have a solid understanding of when to use each one. Here’s a refresher on loops if you need it.
Also, don’t shy away from getting technical with your answers. Explain how you would use the `break` keyword to terminate loops early and the `continue` keyword to pick up where you left off.
7. What databases have you used with PHP?
PHP supports several databases. Some that you might have experience with are MySQL, PostgreSQL, Oracle, MongoDB, and Sybase.
The interviewer might ask you this question because learning how to use a supported database can be very beneficial to a web developer. It also shows that you know how to work with large sets of data with recognized software.
More interview prep
Along with PHP-related questions, you can expect a range of other technical and behavioral questions during your interview. You can use our guide on technical interviews to continue preparing for the interview process.
Need some extra coding practice before your interview? Code challenges are a great way to practice your skills and gain confidence before heading into an interview. Here are 10 PHP code challenges that are specifically designed for beginners.
Learn more about PHP
If you need to brush up on a skill or if you’re looking to take your PHP skills to the next level, our online courses can help. Here are a few to consider: