Php-mysql Course

The splat operator was introduced in PHP starting with version 5.6, so, to can use it and test the examples from this page, you need PHP 5.6+.
The Splat Operator is represented by three dots (...), and can be used to define functions that can be called with a variable number of arguments.

1. This operator can be used when the function is called, before an array argument.
<?php
function add($a, $b, $c) {
  return $a + $b + $c;
}

$arguments = [8, 9];     // array with values for $b and $c parameters
echo add(5, ...$arguments);      // 22
?>
2. The splat operator can also be used when the function is defined, before a parameter that represents an array of arguments.
<?php
// $params is an array containing the remaining arguments
function add($opt = 0, ...$params) {
  $sum = $opt + array_sum($params);
  echo '$opt is '. $opt .' / $params contains '. count($params .' arguments / $sum = '. $sum;    
}

add();             // $opt is 0 / $params contains 0 arguments / $sum = 0
add(1);            // $opt is 1 / $params contains 0 arguments / $sum = 1
add(5, 6);         // $opt is 5 / $params contains 1 arguments / $sum = 11
add(5, 6, 7);      // $opt is 5 / $params contains 2 arguments / $sum = 18
add(5, 6, 7, 8);   // $opt is 5 / $params contains 3 arguments / $sum = 26
?>

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which type of <input> creates a color well control for selecting a color value?
type="text" type="color" type="date"
<input type="color" name="get_color" />
Which CSS method rotates the HTML element at a given degree?
scale() translate() rotate()
#some_id:hover {
  transform: rotate(60deg);
  -ms-transform: rotate(60deg);    /* IE 9 */
  -moz-transform: rotate(60deg);   /* Firefox */
}
Click on the function that returns the number with the highest value.
pow() min() max()
var maxn = Math.max(8, 4, 88, 56);
alert(maxn);      // 88
Which function prevent the same file from being included more than once in a page?
include() include_once() require()
include_once("some_file.php");
Splat Operator in PHP

Last accessed pages

  1. CSS cursor property - Custom Cursors (6423)
  2. jQuery get() and post() (2204)
  3. Zodiac Signs JavaScript code (11204)
  4. Integer and Float value in Select with PDO from string to numeric (8687)
  5. Get Lower, Higher and Closest Number in JavaScript (3341)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (88)
  2. PHP-MySQL free course, online tutorials PHP MySQL code (27)
  3. CSS cursor property - Custom Cursors (24)
  4. The Mastery of Love (18)
  5. PHP Script Website Mini-Traffic (15)