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 HTML5 tag is indicated to be used as container for menu with navigation links in Web site?
<section> <nav> <article>
<nav><ul>
 <li><a href="http://coursesweb.net/css/" title="CSS Course">CSS Course</a></li>
 <li><a href="http://www.marplo.net/jocuri/" title="Flash Games">Flash Games</a></li>
</ul></nav>
Which CSS property shifts an item horizontally to the left or right of where it was?
text-align clear float
.some_class {
  width: 30%;
  float: left;
}
Click on the Math object method which returns x, rounded downwards to the nearest integer.
Math.ceil(x) Math.abs(x) Math.floor(x)
var num = 12.34567;
num = Math.floor(num);
alert(num);       // 12
Indicate the PHP function which returns the number of characters in string.
mb_strlen() count() stristr()
$str = "string with utf-8 chars åèö";
$nrchr = mb_strlen($str);
echo $nrchr;        // 30
Splat Operator in PHP

Last accessed pages

  1. Last Google Cache of Web Page (1495)
  2. Get CSS property value with getComputedStyle ot jQuery (5530)
  3. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (55409)
  4. Redirects (4788)
  5. Add sounds and audio effects in Flash (3457)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (198)
  2. Read Excel file data in PHP - PhpExcelReader (72)
  3. The Four Agreements (65)
  4. PHP Unzipper - Extract Zip, Rar Archives (63)
  5. Get and Modify content of an Iframe (49)
Chat
Chat or leave a message for the other users
Full screenInchide