PHP Question: Variable Reference
QuestionWhat does the following code snipped print?1 2 3 $a=5;$b='a';print$$b;AnswerThis will print "5" because $$b tells PHP to use the value of the $b variable as a variable name, so as the value of...
View ArticlePHP Question: Pass By Reference
QuestionConsider the following:1 2 3 4 5 6 function doSomething(&$val){ $val++;} $a=1; doSomething($a);What does the variable $a now equal?AnswerThe answer here is '2' because the variable $a...
View ArticlePHP Question: Form Variables
QuestionGiven the following form:1 2 3 4 <form method="post" action="index.php"><input type="input" value="" name="text"/><input type="submit" value="Submit"/></form>How would...
View ArticlePHP Question: Object Property Increment
QuestionWhat does the following snippet print and why?1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?phpclass MyClass { public$value;} function doSomething($object){ $object->value++;} $a=new...
View ArticlePHP Question: Print Object
QuestionThe following code was executed.1 2 3 4 5 6 7 <?phpclass MyClass { private$foo="bar";} $myObject=new MyClass();echo$myObject;Which produced the following error.1 2 3 4 Catchable fatal...
View ArticlePHP Question: PHP Script Shape
QuestionWrite a PHP script that will print out the following text in the correct diamond shape.1 2 3 4 5 6 7 8 9 10 * *** ***** ******* ********* ********* ******* ***** ***...
View ArticlePHP Question: Class Methods
QuestionWhat is the difference between these two lines of code and can you produce the background code used for them?1 2 3 4 5 // Line 1$MyClass->MyMethod(); // Line 2 MyClass::MyMethod();AnswerThe...
View ArticlePHP Question: Defining Constants
QuestionWhat does the following code do? define("MY_CONSTANT",array(1,2,3,4,5));AnswerIf this code is run it will produce the following error:Warning: Constants may only evaluate to scalar values in...
View ArticlePHP Question: While And Do While Looping
QuestionWhat does the $count variable equal after each of these loops?1 2 3 4 5 6 // Loop 1 - while$count=0; while($count<0){ ++$count;}1 2 3 4 5 6 // Loop 2 - do while$count=0; do{...
View ArticlePHP Question: Post Variables
QuestionTake the following HTML form.1 2 3 4 <form id="form" name="form" method="post"> <input type="text" name="number" value="0" /> <input type="submit" /> </form>What is the...
View Article