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 tag is used to add lists into <ul> and <ol> elements?
<dt> <dd> <li>
<ul>
 <li>http://coursesweb.net/html/</li>
 <li>http://coursesweb.net/css/</li>
</ul>
Which value of the "display" property creates a block box for the content and ads a bullet marker?
block list-item inline-block
.some_class {
  display: list-item;
}
Which instruction converts a JavaScript object into a JSON string.
JSON.parse() JSON.stringify eval()
var obj = {
 "courses": ["php", "javascript", "ajax"]
};
var jsonstr = JSON.stringify(obj);
alert(jsonstr);    // {"courses":["php","javascript","ajax"]}
Indicate the PHP class used to work with HTML and XML content in PHP.
stdClass PDO DOMDocument
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>';
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById("dv1");
echo $elm->nodeValue;    // CoursesWeb.net
Splat Operator in PHP

Last accessed pages

  1. Shape Tween - Flash Animation (6149)
  2. The Mastery of Love (7440)
  3. Get Mime Type of file or string content in PHP (6230)
  4. Countdown Timer with starting time added into a form (11533)
  5. Disable button and Enable it after specified time (17533)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (477)
  2. CSS cursor property - Custom Cursors (81)
  3. The Mastery of Love (72)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (64)
  5. CSS3 2D transforms (46)