PHP

PHP

Test your PHP knowledge with free quizzes on MyCodeSkills covering core concepts.


  1. Which of the following is the correct way to start a PHP block?

    • <script>
    • <php>
    • <?php
    • <%php
  2. What is the correct way to end a PHP statement?

    • :
    • .
    • ;
    • ,
  3. How do you declare a variable in PHP?

    • var name;
    • $name;
    • name = $value;
    • $name = value;
  4. What will echo "5" + "5" output?

    • 55
    • 10
    • Error
    • 5+5
  5. Which of the following is a valid PHP variable name?

    • $1name
    • $name_1
    • 1$name
    • name$
  6. What does the explode() function do?

    • Combines arrays
    • Splits a string into an array
    • Joins strings
    • Deletes arrays
  7. Which function reads a file line-by-line into an array?

    • fopen()
    • file()
    • fread()
    • readfile()
  8. What is the purpose of session_start()?

    • Start file download
    • Start output buffering
    • Start a new session or resume one
    • Create a cookie
  9. How can you delete a cookie in PHP?

    • delete_cookie()
    • unset($_COOKIE['name'])
    • setcookie('name', '', time()-3600);
    • remove_cookie('name')
  10. Which function returns the number of characters in a string?

    • len()
    • count()
    • strlen()
    • size()
  11. What does the __autoload() function do in PHP?

    • Automatically loads missing variables
    • Automatically loads classes when they are referenced
    • Automatically includes config files
    • Automatically loads templates
  12. Which PHP feature allows you to share code between classes without inheritance?

    • Interfaces
    • Traits
    • Abstract Classes
    • Namespaces
  13. What does the final keyword do when used in a class?

    • Prevents the class from being inherited
    • Makes all properties read-only
    • Forces constructor execution
    • Allows partial overriding
  14. Which of the following is a common design pattern used in PHP?

    • For Loop
    • Singleton
    • While Chain
    • Array Factory
  15. What is the main purpose of using Composer in PHP?

    • Run JavaScript files
    • Manage CSS files
    • Manage dependencies and autoloading
    • Connect to MySQL