PHP Study Set

The flashcards below were created by user caldreaming on FreezingBlue Flashcards.

  1. PHP stands for _____________________.
    PHP Hypertext Preprocessor
  2. When PHP was originally released in 1994, what did PHP stand for?
    Personal Home Page
  3. PHP 4.0 was released in 2000 and it's core was rewritten and named ___________________.
    Zend Engine
  4. What version of PHP are we working with in 2016?
    PHP version 7.0  (7.0.1   released 12/15)

    Version 6.0 was skipped because there was issues with Unicode so instead of releasing version 6.0, the Unicode functionality of Version 6.0 was added to a minor release of 5.0 and Version 6.0 was skipped entirely.
  5. Which is the correct syntax for declaring a variable in PHP?

    A) message="Hello World!";
    B) $message="Hello World!";
    C) message=Hello World!;
    D) $message=Hello World!;
    B) $message="Hello World!";
    (this multiple choice question has been scrambled)
  6. Which is the correct syntax for opening a PHP script?

    A) <?php
    B) <php>
    C) <php
    D) <doctype php
    A) <?php
    (this multiple choice question has been scrambled)
  7. Which is the correct message for sending the following variable to the screen?

    $message="Hello World!";

    A) echo ("$message");
    B) echo ($message);
    C) document.write($message);
    D) echo $message;
    D) echo $message;
    (this multiple choice question has been scrambled)
  8. T/F:  All PHP scripts need a closing PHP tag; ?>

    A) True
    B) False
    B) False

    The closing PHP tag is only needed if the script is going to contain HTML.
  9. T/F:  PHP is a weakly typed language meaning that we do not have to declare a variable type before declaring a variable.

    A) True
    B) False
    A) True

    In PHP you do not have to declare a type in order to declare a variable.  Both of the following examples are correct;

    • $message="Hello World!";
    • $message="12.5";
  10. The shorthand version for printing out a variable inside HTML code is;

    A) <php echo $message>
    B) <?=$message?>
    C) <?$message?>
    B) <?=$message?>

    <?=$message?> is the same as <?php echo $message ?>
    (this multiple choice question has been scrambled)
  11. What is the difference between string builder and string buffer?
    String is an immutable object which means the value cannot be changed where as StringBuffer is mutable. The StringBuffer is Synchronized hence thread safe where as StringBuilder is not and suitable for only single threaded instances.

    For asynchronous access string buffer is multi-threaded whereas string builder is single-threaded.
  12. What is PHP?
    PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and CMS for creating websites. Even a non-technical person can create sites using its CMS. WordPress, osCommerce are the famous CMS of php. It is also an object oriented programming language like java, C-sharp etc. It is very easy to learn.
  13. What is the use of "echo" in PHP?
    • It is used to print data in the webpage,
    • Example: <?php echo 'Car insurance'; ?>

    echo and print are very similar commands however it is important to know that the print statement is a little slower in execution than the echo command.

    Echo has no return value while print has a return value of 1 so it can be used in expressions.  

    Echo can take multiple parameters (though little used) while print can take one argument.
  14. What methods are available to include a file on a PHP page?
    We can include a file using "include() " or "require()" function with file path as its parameter.
  15. What's the difference between include and require?
    If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
  16. What is the difference between the following methods;  require_once(), require(), include()?
    require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.
  17. What are the differences between the GET and POST methods ?
    We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method.
  18. How can you declare an array in PHP?
    Eg : var $arr = array('apple', 'grape', 'lemon');
  19. What is the use of 'print' in PHP?
    This is not actually a real function, It is a language construct. So you can use it without parentheses with its argument list.  The print function outputs to the screen like the echo() function however it is slightly slower in performance.

    Example print('PHP Interview questions'); print ('Job Interview ');
  20. What is the purpose of the function in_array() in PHP?
    in_array is used to check whether a value exists in an array.

    Example: Search for the value "Glenn" in an array and output some text;

    • <?php
    •     $people=array("Peter", "Joe", "Glenn", "Robert");

    • if (in_array("Glenn", $people))
    •     {echo "Match Found";
    •       }
    •     else
    •     {echo "Match Not Found";
    •       }
    • ?>
  21. What is the use of count() function in PHP?
    count() is used to count all elements in an array, or something in an object.

    Example: Return the number of elements in an array

    • <?php
    • echo count($people);
    • ?>

    Returns the number of people in the array list.
  22. What’s the difference between include and require?
    It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
  23. What is the difference between Session and Cookie?
    The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies cannot hold multiple variables, But Session can hold multiple variables. We can set expiration for a cookie, The session only remains active as long as the browser is open. Users do not have access to the data you stored in Session, Since it is stored in the server. Session is mainly used for login/logout purpose while cookies are used for user activity tracking.
  24. How do you set cookies in PHP?
    Setcookie("sample", "ram", time()+3600);
  25. How do you retrieve a Cookie value?
    eg: echo $_COOKIE["user"];
  26. How do you create a session?
    Create session: session_start();
  27. How do you set a value in session ?
    Setting a value in session:

  28. How do you Remove data from a session?
    Removing data from a session:

  29. What types of loops exist in PHP?
    There are 4 loop structures;

    for, while, do while and foreach

    Example:  foreach loop

    • <?php
    •      $colors = array("red", "green", "blue");

    •      foreach($colors as $value) {
    •           echo "$value <br>";
    •      }
    • ?>
  30. How do you create a mysql connection in PHP?
  31. How do you select a particular database in PHP?
  32. How do you execute an MSSql query in PHP?
    $my_qry = mysql_query("SELECT * FROM `users` WHERE `u_id`='1'; ");

    • To retrieve and display the results:
    • $result = mysql_fetch_array($my_qry);
    • echo $result['First_name'];
  33. What is the proper syntax to write a while loop in PHP?
    • $my_qry
    • = mysql_query("SELECT * FROM `users` WHERE `u_id`='1'; ");

    • while($result = mysql_fetch_array($my_qry))
    •     {
    •         echo $result['First_name'.]."<br/>";
    •     }
  34. How we can retrieve the data in the result set of MySQL using PHP?
    • 1. mysql_fetch_row
    • 2. mysql_fetch_array
    • 3. mysql_fetch_object
    • 4. mysql_fetch_assoc
  35. What is the use of explode() function in PHP?
    Syntax: array explode ( string $delimiter , string $string [, int $limit ] );

    • This function breaks a string into an array.
    • Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
  36. Name some PHP frameworks;
    • Laravel -  Laravel is a PHP web application framework with expressive, elegant syntax, aiming to take the pain out of web development by easing common tasks, such as authentication, routing, sessions and caching.
    • CodeIgniter - CodeIgniter is a powerful PHP framework with a small footprint, built for those who required a simple, yet elegant toolkit to build fully-featured web applications. It requires nearly zero configuration, with no restrictive coding rules, and offers simple solutions to complex application requirements. 
    • CakePHP - CakePHP enables you to build web applications faster, using code generation features to rapidly build prototypes. There is no complicated configuration, just setup your database and you're ready to go. Translations, database access, caching, validation, authentication and more are all built into the framework. It comes packaged with clean MVC conventions, to guide you in developing your application. CakePHP can handle every aspect of your application, from the user's initial request all the way to the final rendering of a web page. The framework provides a basic organizational structure, from filenames to database table names, to keep your entire application consistent and logical. CakePHP also comes with built-in tools for validation and protection against SQL injection, form tampering and more, to help keep your application safe and secure. 
    • Symfony - Symfony is a PHP framework to speed up the creation and maintenance of your web applications. By using existing 'de facto' standards of PHP, such as PHPUnit, and naming conventions for classes, you're not confined within the Symfony environment, but instead have the freedom to choose the software components that you want to use. It provides a set of prefabricated components that can be rapidly integrated into your application, combined with a clear methodology to help you work both efficiently and effectively on the most complex tasks. The use of Best Practices guarantees the stability, maintainability and upgradeability of any application you develop. You can choose the Full Stack (complete) version if you want to develop a complex application, or Brick by Brick, to build your own framework according to the functionality you need, or Microframework, as a standalones used to develop specific functionality in your project.
    • Zend Frmework 2 - Zend Framework 2 is an open-source framework for developing web applications, using object-oriented code. The components in the standard library form a powerful an extensible framework when combined, offering a robust, high performance MVC implementation. It's easily extensible, adapting to your needs, with a modular base so you can use building blocks in combination with other applications or frameworks. Using the ZendService you can implement client libraries to access the most popular web services available. As Zend is a collection of classes, you can just load the components you need, to take advantage of the components as individual libraries, instead of the framework as a whole, cutting down on unnecessary project bloat. With no model implementation you are free to implement the framework and components in whatever way you need, free of predefined restraints.
    • Phalcon - Phalcon is a PHP 5 framework that is implemented as a C extension to offer lower resource consumption and high performance. There's no need to learn or use the C Language, as the functionality is exposed as PHP classes ready to use. As Phalcon is loosely coupled, you're free to use the full framework, or just specific parts of it as glue components. Rather than download an archive, extracting it to a directory like you do with most frameworks, Phalcon can be downloaded and installed as a PHP module. By creating a rich, fully featured framework written entirely in C and packaged as a PHP extension, Phalcon is able to save processor time and boost overall performance. While it is just under two years old, the Phalcon documentation, community and development rival that of many of the more mature frameworks available. 
    • PHP-MVC  - PHP-MVC is an extremely simple but effective Model-View-Controller application structure which is clean, easy to learn, highly documented and features a self-explaining structure and optional Composer integration. It comes in two versions, a basic and advanced, with the advanced version featuring additional Twig support and automatic SASS compiling in pure PHP. It is not a fully featured framework but instead provides a bare-bone structure, aiming to be extremely slimmed down. It's as simple and readable as possible, with a skeleton structure for quick application building, especially useful for those new to PHP. The project encourages coders to work according to PSR 1/2 coding guidelines, promoting the usage of PFO, and the use of external libraries via Composer. As it only uses native PHP code, there's no need to re-learn a framework, so you can get started straight away.
  37. What are the differences between the echo and the print methods to get output?
    • 1. Echo is slightly faster than print
    • 2. Echo has no return value while print has a return value of "1" and can be used in expressions
    • 3. Echo can take multiple parameters while print can only take one argument
Card Set:
PHP Study Set
2016-02-17 13:01:57
php hypertext preprocessor programming software server side language study

PHP Study card set
Show Answers: