PHP INTERVIEW QUESTIONS

    

 PHP INTERVIEW QUESTIONS

1. WHAT IS PHP?

PHP (Hypertext Preprocessor) is a server site scripting language designed for web development. It is widely used foe creating dynamic and interactive website. 

2 . Difference between echo and print?
echo is faster then print, can print multiple values,  No return value.
print slower, return 1 (true) prints on;y one value

echo "Hello", " World!";  // ✅ Works
print "Hello", " World!"; // ❌ Error

3. Difference between variable and constants? 

Both variables and constants store data, but they behave differently. 

variable can changeable constants cannot be modify after declaration 
variable have local and global scope, while constants are always global 

4. what are the different data type in PHP?

PHP has 8 primary data types 
    
Data Type

Example

Description

String"Hello"   Sequence of characters
Integer10   Whole number
Float10.5     Decimal number
Booleantrue / false   Logical values
Array[1, 2, 3]   Collection of values
Objectnew ClassName()   Instance of a class
NULLNULL   No value
Resource      mysqli_connect()   External resource (e.g., database)

5. What is difference between NULL and 0?

   Both NULL and 0 represent "nothing",  but they are different
    . NULL -:  no value assigned  
    . 0 -:  Numeric value zero.

6. Difference between == and === ?

    ==  checks value only 
    === checks  value and data type 

var_dump(2 == "2");  // true (only checks value)
var_dump(2 === "2"); // false (checks value & type)
 

7. What is function is PHP?

    A function is a block of code that can be reused.

    function greet() {
        return "Hello, World!";
  }
  echo greet();

8. How do you return a value for a function?

    To using a return keyword. 

function add($a, $b) {
    return $a + $b;
}
echo add(5, 3); // 8


Comments

Popular posts from this blog

PHP Intermediate Questions Interview Preparation

PHP Interview Questions (Beginner Level) – Short Answers