1. $a = "a";
    $a .= "b";
    $a .= "c";

    What is the value of $a ?

  2. The value of A is abc

    Explanation: the full stop appends the next value to the value within the variable.

  3. $a = 4;
    $c = 0;
    for ($b = 0; $b <= $a; $b++) {$c++;}

    What is the value of $c ?

  4. The value of C is 5

    Explanation: As the variable b starts from 0 there are 5 iterations within the for loop, this increments the variable C 5 times.

  5. $a[] = "a";
    $a[] = "b";
    $a[] = "c";

    What is the value of $a[2] ?

  6. The value of a[2] is c

    Explanation: The initial code appends the values to the array. Arrays start from 0, this makes element 2 the third element in the array.

  7. $a = "abc";
    $b = substr($a, 0, -1);

    What is the value of $b ?

  8. The value of b is ab

    Explanation: When selecting chars from strings they start at position 0, the length value, given as negative is the equivalent of mb_strlen($a) - 1. This means that the string selected will be of length 2, thus, ab.

  9. $a = "b";
    $b = "a";

    What is the value of ${$b} ?

  10. The value of $$b is b

    Explanation: Known as variable variables, the value of $b is used as the name of the variable that should be returned. In this instance the value of the variable a, is b.

  11. $a = "post_processed_string";
    $b = array("post_", "_");
    $c = array("", " ");
    $d = ucwords(str_replace($b,$c,$a));

    What is the value of $d ?

  12. The value of d is Processed String

    Explanation: str_replace takes the arguments, string to find, string to replace, string to search. When arrays are passed as the arguments the arrays are processed so element 0 in the find array is replaced with element 0 from the replace array. Thus post_ is replaced with nothing and _ is replaced by a space. The function continues until all array elements have been processed. Once the function has finished the remaining string is 'processed string'. This string is then passed to the function ucwords which converts the first character of each word to upper case.

  13. Reverse the string 'Manhattan'

  14. The reversed string is nattahnaM

    Code: $a = strrev("Manhattan");
    echo($a);

  15. Create a Person class with Height, Weight and Gender properties.

  16. Class Code:

    Class Person{
    public $Height;
    public $Weight;
    public $Gender;
    }

  17. Write a function that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

  18. 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz

    Code as written:
    	for ($x = 1; $x <= 100; $x++) {
    		if ($x % 3 == 0) {
    			echo("Fizz");
    		}
    		if ($x % 5 == 0) {
    			echo("Buzz");
    		}
    		if (($x % 3 != 0) and ($x % 5 != 0)) {
    			echo($x);
    		}
    		if ($x < 100) {
    			echo(", ");
    		}
    	}
    
    I have written it this way for efficiency. As I am already checking for both x mod 3 being 0 and x mod 5 being 0 I can utilise this to also check for numbers that qualify for FizzBuzz if I structure my code correctly. This saves me a few lines of code making the script more efficient.