Request Dev Services »

PHP Trivia – Gotchyas?

Q. If you attempt to declare a variable without _________________________ it, you will receive an error.

     A. Initializing

Q. Data types that can be assigned only a single value are called _________________________.

    A. Primitive Type

“Today, let’s examine the three Ps: Perl, PHP and Python. All these three languages are dynamic and powerful in their own way and can be used in different scenarios, but they are most commonly used to build Web applications and for scripting. Perl is a general-purpose, high-level, dynamic programming language.” –

Q. Explain loops in PHP?


   for − loops through a block of code a specified number of times.

   while − loops through a block of code if and as long as a specified condition is true.

   do…while − loops through a block of code once, then repeats loop as long as special condition is true.

   foreach − loops through a block of code for each element in an array.

foreach could be modified and used similar as a do…while loop, by adding a break to meed a condition

foreach ($array as $value){ if($condition != true) break; }

The for, for..while, and do..while are essentially all doing the same thing aside from adding pre and post-loop conditions before or after loop fires. I believe they could really all be modified and used interchangeable if determined and really needed such as the foreach example.

Q. A _________________________is a variable that is declared outside a function and is available to all parts of your program.

   A. global

Q.  ________________________ are declared inside a function and are only available within the function in which they are declared.

   A. local

Q.  The foreach statement is used to iterate or loop through the elements in a(n) _________________________.

   A. array

Q. The _________________________ statement controls program flow by executing a specific set of statements, depending on the value of the expression.

   A. switch

Q.  Explain break and continue.


continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.

break ends execution of the current for, foreach, while, do-while or switch structure.

The difference?


 ends a loop completely, 


 just shortcuts the current iteration and moves on to the next iteration.

while ($foo) { --------------------continue; --- goes back here --break; ----- jumps here ----} |--------------------

Q. Unlike other programming languages, PHP has no special data type for a(n) _________________________ character.

   A. string

Q.  What is the most commonly used string function, which returns the total number of characters in a string?


'strlen() Function' ie. 'echo strlen("Hello");'

Q. Under what circumstances would you want to convert a text string to a numerical data?


When, from a variable you need or require numeric data, not text or a word. Such cases as needing numeric data to do math operations on in the future etc. Or another scenario could be pertaining to zip codes in web forms. 

“This situation happens when a visitor submits a form which contains a numeric field(ex. zipcode), but, when you try to get the value in the next page, it shows as a string.” –


preg_match — Perform a regular expression match
==operator, Returns true if $x is equal to $y

strcmp() can serve in place of == because it returns 0 when two strings are equal. There is an urban myth amongst PHP programmers that == is faster than strcmp(), however the reality is that it is just as fast, and you can use the two interchangeably if you wish. One thing, though: using ==, you get a “1” if two strings match, whereas with strcmp() you get a 0″ –

preg_match however is most different from the two as it executes with regular expressions; which is also said to be a more expensive approach in the longer run with execution and strpos should be considered first.

Q.  The _________________________ method is the preferred way to transfer form data to the processing script.

   A. POST

Q. To, Subject, and Message are the three required arguments of the _________________________ function.

   A. mail function

Q. In PHP the _________________________ function is used to change the permissions on a file.

   A. chmond()

Q. The _________________________ function prevents multiple users from modifying a file simultaneously.

   A. flock()


You can pass an associative array as a parameter and it will convert into the default index of the array. In example: starting with 


 after the call to the function the array can be  


Q. To add or remove elements from the beginning of an array, you need to use the array_shift() and _________________________ functions.

   A. array_unshift

Q. You can use the _________________________ function to determine whether a given index or key exists.

   A. array_key_exists() 

 Q. To add or remove elements from the beginning of an array, you need to use the array_shift() and _________________________ functions.
   A. array_unshift

Q. Each column in a database table is called a(n) _________________________.

   A. field 

Q. You can select unique values from a table using the _________________________keyword.


Q. For large datasets stored in external files, it is more efficient to use the _________________________ statement to add multiple records to an existing table.

   A. Load Data

Q. The triple equal sign (===) verifies that the two variables not only parse to be the same, but they are of the same _________________________

   A. type and value

Q.  Use the _________________________ function to send SQL statements to MySQL.

   A. mysql_query()


“Non-relational databases, also called NoSQLdatabases, the most popular beingMongoDB, DocumentDB,Cassandra, Coachbase, HBase, Redis, and Neo4j.” describes James Serra’s technical blog on the topic at “Relational databases like MySQL, PostgreSQL and SQLite3 represent and store data in tables and rows. They’re based on a branch of algebraic set theory known as relational algebra. Meanwhile, non-relational databases like MongoDB represent data in collections of JSON documents. The Mongo import utility can import JSON, CSV and TSV file formats. Mongo query targets of data are technically represented as BSON (binary JASON).” describes Jacqueline Homan in here relevant article at ‘’.

Q. Cookies created with only the _________________________ and _________________________ arguments are temporary cookies because they are available for only the current browser session.

   A. name and value arguments 

Q. To store persistent data about a Web site visit, with hidden form fields, query strings, cookies, and sessions is called _________________________.

   A. Maintaining state


“The object-oriented modeling approach creates the union of the application and database development and transforms it into a unified data model and language environment. Object-oriented modeling allows for object identification and communication while supporting data abstraction, inheritance and encapsulation.”  states TechnoPedia at ‘’
About the Author
Cameron Cashwell Web Developer
I build websites, web apps, and software. Wanna work together? Let's chat about your project!

Leave a Reply

Notify of