Site icon sharedsapience.info

PHP Array Function Quiz: current(); each(); end(); extract(); in_array(); key(); and krsort().

First two rows of the PHP mini-quiz, sized for desktop viewing.

Image of the first two rows of the PHP mini-quiz, sized for desktop viewing.

HOW THE QUIZ WORKS:

Clicking the ‘randomize’ button situated above the reference table generates a new table whereby the function descriptions, function syntaxes, and function return values are randomized. The quiz involves matching the function descriptions, function syntaxes, and function return values to the correct function name. Information relating to the randomization of table cells will be displayed for three seconds, before disappearing.

On a desktop computer, table elements are selected by left-clicking the desired table cell and holding the left click in the mouse down position for one second before releasing the left click. The text inside the table cell will turn red to indicate that the one-second mouse left-click has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second left mouse-click process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second left mouse-click process on the original table cell.

To select a table element on a touchscreen device (mobile, tablet), simply touch the desired table cell and maintain the touch for one second before removing your finger from the screen. The text inside the table cell will turn red to indicate that the one-second touch has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second touch process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second touch process on the original table cell.

Normal touchscreen scrolling behaviour is exhibited by the cells with a light green background; cells without a light green background will not respond to normal touchscreen scrolling. The table is positioned in such a way that the user can also initiate touchscreen scrolling by swiping to the right or left of the table.

When a row consists of the correct function name, function description, function syntax, and function return value, the background colour of the row will change from ‘transparent’ to ‘khaki’; this provides visual feedback that the row is complete.

Once the entire table is complete, a paragraph of feedback will congratulate the user and provide the following information: date and time of quiz commencement; date and time of quiz completion; and the length of time it took the user to complete the quiz.

VIEWPORT OPTIONS:

An example of the layout designed for mobile phones
An example of the layout designed for tablets
An example of the layout designed for desktop computers

PURPOSE:

This webpage serves two purposes:

  1. It provides a reference table for the PHP array functions, with information extracted and condensed from w3schools.com and php.net.
  2. It enables users to complete a quiz related to the PHP array functions.

USAGE:

For each array function there are four table cells of information: the function name; the function description; the function syntax; and the function return value. There are three layouts available – ‘mobile‘, ‘tablet‘, and ‘desktop‘.

Click the relevant button below to display the PHP array functions reference table, sized appropriately for the desired viewport. A ‘RANDOMIZE‘ button appears above the reference table once the viewport is selected; clicking this button facilitates the commencement of a quiz.



Once the randomization of function descriptions, function syntaxes, and function return values has taken place, an ‘AUTO COMPLETE‘ button will appear above a button that facilitates a ‘RETURN TO VIEWPORT SELECTION‘. Clicking the ‘AUTO COMPLETE‘ button initiates a ‘self-completing quiz’ effect: the table cells will be correctly rearranged before your eyes in real-time. This ‘self-completion in real-time’ lasts approximately one-and-a-half minutes. You can rearrange the cells in any order that you like before clicking the ‘AUTO COMPLETE‘ button – the quiz will still ‘complete itself’.

Click the ‘RANDOMIZE‘ button to randomize the functional descriptions, the functional syntaxes, and the functional return information.



FUNCTION NAME FUNCTION DESCRIPTION FUNCTION SYNTAX FUNCTION RETURN VALUE
current()

[Return the current element in an array]

Every array has an internal pointer to its current element, which is initialized to the first element inserted into the array.
This function does not move the internal pointer in any way. Alias of pos().
current(array);

[As of PHP 7.0.0 array is always passed by value; beforehand, it was passed by reference whenever possible.]

Returns the value of the array element that is currently being pointed to by the internal pointer. If the internal pointer points beyond the end of the elements list or the array is empty, FALSE is returned.
each()

[Return the current key and value pair from an array and advance the array cursor]

Advances the array cursor after returning the current key and value pair from array. This function has been deprecated as of PHP 7.2.0. each(array); Returns the current key and value pair from array. This pair is returned in a four-element array, with the keys 0, 1, key, and value. Elements 0 and key contain the key name of the array element, while 1 and value contain the data. FALSE is returned if the internal pointer points past the end of the array contents.
end()

[Set the internal pointer of an array to its last element]

Propels array‘s internal pointer to its last [‘end’] element and returns the value. end(array);

[array is passed by reference.]

Returns the value of array‘s last element, or FALSE for an empty array.
extract()

[Import variables into the current symbol table from an array]

Extracts variables from array and imports them into the current symbol table. Each key is checked to see whether it has a valid variable name. A check for collisions with existing variables in the symbol table also occurs. array must be an associative array, since this function treats keys as variable names and values as variable values; a numerically-indexed array will not produce results unless either the EXTR_PREFIX_ALL or the EXTR_PREFIX_INVALID flag is used. extract(array, extract_flag [optional], extract_prefix [optional]);

[extract_flag comprises the following options: EXTR_OVERWRITE [default]; EXTR_SKIP; EXTR_PREFIX_SAME; EXTR_PREFIX_ALL; EXTR_PREFIX_INVALID; EXTR_IF_EXISTS; EXTR_PREFIX_IF_EXISTS; EXTR_REFS.]

Returns the number of variables successfully extracted and imported into the symbol table.
in_array()

[Checks if a value exists in an array]

Searches in array for value, using loose comparison unless strict is set. If value is a string, the comparison is performed in a case-sensitive manner. in_array(value, array, strict [optional]);

[If strict is set to TRUE then the types of search value and array values are also compared.]

Returns TRUE if value is found in array; otherwise FALSE.
key()

[Fetch a key from an array]

Returns the index element of the current array position. This function does not move the internal pointer in any way. key(array);

[As of PHP 7.0.0 array is always passed by value; beforehand, it was passed by reference whenever possible.]

Returns the key of the array element that is currently being pointed to by the internal pointer. NULL is returned if the internal pointer points beyond the end of the elements list, or if array is empty.
krsort()

[Sort an array by key in reverse order]

Sorts array by key in reverse order, maintaining key-data correlations. krsort(array, sort_flag [optional]);

[sort_flag options: SORT_REGULAR; SORT_NUMERIC; SORT_STRING; SORT_LOCALE_STRING; SORT_NATURAL; and SORT_FLAG_CASE.]

krsort(): returns TRUE on success; FALSE on failure.

Web design certified by:
Click images for proof of certification.

Exit mobile version