PHP Interview questions – vlog Part 1

Authored By : Tejaswi Reddy

PHP stands for PHP – Hypertext Preprocessor an open source server side scripting language which is widely used for creating dynamic websites & API’s for mobiles

PHP supports many databases like MYSQL, MongoDB, PostgreSQL, Oracle, Sybase etc.

Basic PHP questions
  1. What are data types?
  2. What is a variable?
  3. What are constants?
  4. What is session in PHP?
  5. What is an array and its types?
  6. Can we create an array from string?
  7. How do you concatenate 2 variables?
  8. What are cookies & how to create cookies in PHP?
  9. Which is faster switch or if and why?
  10. Magic methods in PHP.
  11. What is the function used to delete an image in PHP?
  12. Explain implode.
  13. What is explode?
  14. When i = 0 return a & when i = 1 return b without using if condition.
  15. What is CURL?
  16. List some features of PHP 7.
  17. What are the ways to include file in PHP?
  18. Is there any function to send email in PHP? if so what is it?
  19. How do you create a database connection in PHP?
  20. Is there any way to stop the execution of PHP Script?
  21. What is .htaccess & its uses.
  22. How can we get IP address in PHP?
  23. How to get browser properties in PHP?
  24. Is PHP Case sensitive?
  25. What is the default file called in PHP?
  26. What is String in PHP?
  27. Different string functions in PHP?
  28. How do you replace a string in PHP?
  29. How do you get the length of a string in PHP?
  30. How do you get last character of a string?
  31. Different ways to declare a constant in PHP.
  32. How can you tell if a number is even or odd without using any condition or loop?
  33. Find no. of days between two days.
Differences
  1. Difference between echo & print.
  2. Difference between implode & explode.
  3. Difference between session & cookies.
  4. Difference between include & require.
  5. Difference between count & sizeof.
  6. Difference between $message & $$message
  7. Difference between associative & indexed array.
  8. Difference between array_merge & array_combine
  9. Difference between push & pop.
  10. Difference between PHP 7.2 & 7.4
  11. Difference between is_array & in_array.
  12. Difference between empty & null
  13. Difference between isset & empty
  14. Difference between const & define in PHP.
  15. Difference between include_once & require_once
  16. Difference between substr & strstr
Arrays
  1. What is an array?
  2. How to get number of elements in an array?
  3. How do you create an array from PHP string.
  4. Different types of arrays available in PHP, Explain.
  5. List any 5 array functions in PHP.
  6. How do you delete an element from an array.
  7. Is there any way to add a new element at the beginning of an existing array?
  8. How to convert a JSON String into array in PHP?
  9. How to remove duplicate values in PHP?
  10. How to get random value from PHP array?
  11. How do you split a string from an array?
  12. How to display array structure & values in PHP?
  13. How to check if a variable is array or not?
  14. How to change array index in PHP?
  15. How to get second last element of array in php?
  16. Use of array_chunk in PHP?
  17. How to add key & value in an array?
OOPS Concepts
  1. What is Stdclass & uses
  2. What is an object & class
  3. What is recursive class in PHP.
  4. What are constructor and destructor in PHP?
  5. What is an interface in PHP?
  6. What is final keyword & when it is used?
  7. What are access modifiers or visibility in PHP? Explain.
  8. What is abstraction and encapsulation?
  9. What is static keyword in PHP?
  10. What is Traits in PHP?
  11. Namespaces in PHP?
  12. Difference between abstract class & interface.
  13. What is extends in PHP?
  14. Can we use multiple inheritance in PHP?
Find the Output
  1. What will be the output of $a & $b for below code?
    $a = ‘1’;
    $b = &$a;
    $b = “2$b”;
  2. What will be the output?
    $a = 10;
    $b = &$a;
    $c = $b/2;
    echo ($a+$c)*3 – 2;
  3. Arrange the following array into ascending order without using pre defined array functions.
    $arr=array(5,6,7,8,9,10);
    $arr1=array(8,9,10,11,2,3,4);
  4. Will be below code executes successfully?
    $a = “PHP”;
    $a = $a + 1;
    echo $a;
  5. What is the function used to get the following output for below array?
    Original Array
    array(
    ‘0’ => ‘z1’,
    ‘1’ => ‘Z10’,
    ‘2’ => ‘z12’,
    ‘3’ => ‘Z2’,
    ‘4’ => ‘z3’,
    );
    Expected Output
    array(
    ‘0’ => ‘z1’,
    ‘3’ => ‘Z2’,
    ‘4’ => ‘z3’,
    ‘1’ => ‘Z10’,
    ‘2’ => ‘z12’,
    );
  6. What is the output of following code?
    $a=”Something”;
    echo !empty($a)?true:false;
  7. What is the output of below code?
    $n = 10;
    if ($n === “10”)
    echo “n is equal to 10”;
    else
    echo “n is not equal to 10”;
  8. What would be the output of following:
    $array = array(
    1 => “a”,
    “1” => “b”,
    1.5 => “c”,
    true => “d”,
    );
    print_r($array);
  9. show only duplicate values from an array without built-in function PHP.
    array $arr = array(8,9,10,3,4,8,7,9,11,3);
  10. What will be the Output?
    $y = “man”;
    $$y = 100;
    echo $y;
    echo $$y;
    echo $man;
Laravel Framework
  1. What is the latest Laravel version?
  2. Define Composer.
  3. What is an artisan?
  4. How to put Laravel applications in maintenance mode?
  5. define folder structure of laravel.
  6. What is MVC
  7. What are the default route files in Laravel?
  8. What are migrations in Laravel?
  9. What are seeders in Laravel?
  10. What are factories in Laravel?
  11. How to implement soft delete in Laravel?
  12. What are Relationships in Laravel?
  13. What is Eloquent in Laravel?
  14. What is throttling and how to implement it in Laravel?
  15. What are facades?
  16. What is Middleware and how to create one in Laravel?
  17. How to install laravel via composer ?
  18. How to enable query log in laravel?
  19. What is reverse routing in laravel?
  20. How to turn off CRSF protection for specific route in Laravel?
MYSQL
  1. What is indexing?
  2. What is the difference between primary,unique & foreign key
  3. What is SQL Injection
  4. Different types of joins, explain.
  5. Difference between left join & right join
  6. What is left excluding join
  7. Difference between char & varchar
  8. Different data types in MYSQL
  9. How do you find a particular value from comma separated values in MYSQL
  10. Find the second highest salary in MYSQL without using limit and offset
  11. Is it possible to rename database or table name? if so how?
  12. Difference between truncate & drop
  13. What is Scaling in MySQL?
  14. What is the difference between BLOB and TEXT?
  15. What is the command used to create a database using PHP and MySQL?
  16. How can you increase the performance of MySQL SELECT query?
  17. What is the main difference between ‘BETWEEN’ and ‘IN’ condition operators?
  18. Can you tell which of the following WHERE clauses is faster?
    WHERE col * 4 < 16
    WHERE col < 16 / 4
    ANS : If we compare both the statements, then the second WHERE clause would be comparatively faster than the first one. That is because, for the first statement, MYSQL would retrieve the value of ‘col’ for each and every row, multiplied by four. After that, it would compare the result to 16. Also, in the first case no Index can be used, and hence it makes it further slow.
  19. What is the default port for MySQL Server?
  20. Differentiate between FLOAT and DOUBLE?

Leave a Reply

Your email address will not be published.