Php-mysql Course

PHP function that returns an Array with Unique Random Numbers or Letters. The function receives three arguments: the number of items in array ($nri), the lowest number or letter ($min), and the highest number or letter ($max).
/*
 Function to create an array of unique random numbers or letters
 Receives 3 arguments:
   $nri = number of items in array
   $min = the lowest number, or letter
   $max = the highest number, or letter
*/
function randomNrLtArray($nri, $min, $max) {
  // From: https://coursesweb.net/php-mysql/
  // creates an array with values from $min to $max
  $arr = range($min, $max);

  // randomizes the order of the elements in $arr, extracts and keeps the first $nri items
  shuffle($arr);
  $arr = array_slice($arr, 0, $nri);

  return $arr;      // returnns the array
}
- Example: gets an array with 5 random numbers from 1 to 50, and another array with 4 random letters from "A" to "M".
<?php
/*
 Function to create an array of unique random numbers or letters
 Receives 3 arguments:
   $nri = number of items in array
   $min = the lowest number, or letter
   $max = the highest number, or letter
*/
function randomNrLtArray($nri, $min, $max) {
  // From: https://coursesweb.net/php-mysql/
  // creates an array with values from $min to $max
  $arr = range($min, $max);

  // randomizes the order of the elements in $arr, extracts and keeps the first $nri items
  shuffle($arr);
  $arr = array_slice($arr, 0, $nri);

  return $arr;      // returnns the array
}

// array with 5 random numbers from 1 to 50
$nrs = randomNrLtArray(5, 1, 50);

// array with 4 random letters from "A" to "M"
$lts = randomNrLtArray(4, 'A', 'M');

// Test
var_export($nrs);
echo '<br/>';
var_export($lts);
?>
Results:
array (0 => 6, 1 => 23, 2 => 42, 3 => 47, 4 => 8)
array (0 => 'J', 1 => 'D', 2 => 'F', 3 => 'G')

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag adds an image in web page?
<div> <img> <span>
<img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Which of these CSS codes displays the text oblique?
font-style: italic; text-decoration: underline; font-weight: 500;
#id {
  font-style: italic;
}
Click on the jQuery function used to hide with animation a HTML element.
click() hide() show()
$(document).ready(function() {
  $(".a_class").click(function(){ $(this).hide("slow"); });
});
Click on the correctly defined function in PHP.
fname function() {} function fname() {} function $fname() {};
function fname($a, $b) {
  echo $a * $b;
}
Create Array of Unique Random Numbers or Letters

Last accessed pages

  1. The School for Gods (5793)
  2. Register and show online users and visitors (39386)
  3. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (137626)
  4. jQuery Ajax - load() method (10780)
  5. Recursive function to create Multi-Level Menu in JavaScript (5888)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (315)
  2. Read Excel file data in PHP - PhpExcelReader (114)
  3. The Four Agreements (95)
  4. PHP Unzipper - Extract Zip, Rar Archives (91)
  5. The Mastery of Love (85)