PHP Basic Interview Questions and Answers

This article presents a collection of fundamental PHP interview questions covering topics such as asynchronous loops, string manipulation, superglobals, file inclusion, date handling, class inheritance, configuration files, as well as related SQL queries and a regular expression for phone numbers, providing concise answers for each.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP Basic Interview Questions and Answers

1. Asynchronous loop output

Code:

for(var i=1;i<=3;i++){
    setTimeout(function(){
        console.log(i);
    },0);
}

Answer: 4 4 4

2. String split and join

Question: "inhemeter".split('').join(' ') results in?

Answer: i n h e m e t e r (spaces between characters)

3. Accessing GET, POST and uploaded files in PHP

Answer: $_GET, $_POST, $_FILES 4. Incorrect statement about include and require

Options:

A. require generates a warning, include generates a fatal error

B. require is loaded before execution

C. include is loaded at runtime

D. require_once prevents multiple inclusions

Correct answer: A

5. Get the previous day of a given datetime

Question: $time = '2017-05-10 12:34:34' Answer: date('Y-m-d H:i:s', strtotime('-1 day '.$time)) or date('Y-m-d H:i:s', strtotime("-1 day $time")) 6. Call parent class method load() from a subclass

Answer: parent::load() 7. File to configure maximum upload size in PHP

Answer: php.ini 8. SQL to find the highest score for each team

Answer: SELECT TEAM, MAX(SCORE) FROM tableA GROUP BY TEAM; 9. SQL to get total score per team with team name from another table

Answer:

SELECT B.NAME, SUM(A.SCORE) FROM tableA A JOIN tableB ON A.TEAM = B.TEAM_ID GROUP BY B.TEAM_ID;

10. Regular expression to match a mobile phone number starting with '1' and 11 digits long

Answer:

/1\d{10}/
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

questionsanswers
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.