Quiz on AI Interviews Prep Live Training Corporate Training

PHP Introduction.

1. What is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language mainly used for web development.

PHP is used to create dynamic web pages and works well with HTML and databases.

2. Features of PHP

  • Open-source and free
  • Easy to learn
  • Works with HTML
  • Supports databases like MySQL
  • Runs on different platforms

3. Basic PHP Syntax

PHP code is written inside <?php ... ?> tags.


<?php
echo "Hello, World!";
?>
    

4. Variables in PHP

Variables in PHP start with the $ symbol.


<?php
$name = "Alice";
$age = 20;
echo $name;
echo $age;
?>
    

5. Data Types

  • String
  • Integer
  • Float
  • Boolean
  • Array
  • Object

6. Input and Output

PHP commonly uses forms to take input.


<form method="post">
    Name: <input type="text" name="username">
    <input type="submit">
</form>

<?php
echo $_POST["username"];
?>
    

7. Conditional Statements


<?php
$marks = 75;

if ($marks >= 50) {
    echo "Pass";
} else {
    echo "Fail";
}
?>
    

8. Loops


<?php
for ($i = 1; $i <= 5; $i++) {
    echo $i;
}
?>
    

9. Functions


<?php
function add($a, $b) {
    return $a + $b;
}

echo add(5, 3);
?>
    

10. Arrays


<?php
$colors = array("Red", "Green", "Blue");

foreach ($colors as $color) {
    echo $color;
}
?>
    

11. PHP and Databases

PHP is commonly used with MySQL databases.

  • User login systems
  • Data storage and retrieval
  • Dynamic websites

12. Applications of PHP

  • Web applications
  • Content Management Systems (WordPress)
  • E-commerce websites
  • Backend APIs