array

PHP Quiz Script

PHP Quiz Script

Hard coding a graded quiz script in PHP

Quizzes are generally used to test knowledge of a subject.
This is a simple script that will allow you to create a quiz and grade the answers given.

PHP Code:

<?php
$let=array(
"a","b","c","d","e","f","g","h","i",
"j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z"
);
 
//Set a counter to 1
$count = 1;
 
/* What is a perfect score? Usually 100. */
 
$psco=100;
 
/* Deduction for each wrong answer. May be the perfect score divided by the number of questions

Populating checkboxes and select lists from an array

Populating checkboxes and select lists from an array

When you use checkboxes in a form, usually you want to save more than one choice.
You must indicate to PHP that you are submitting more than one piece of data with []

<INPUT TYPE="checkbox" NAME="temperature[]" VALUE="hot">Hot
<INPUT TYPE="checkbox" NAME="temperature[]" VALUE="cold">Cold

After submitting your form, save the array data into database.
You can use the implode function joins array elements into a string, then save that string to the
database.

PHP Code
 

Multi-dimensional arrays

Multi-dimensional arrays

Arrays are 1-dimensional objects.

A multi-dimensional array can be considered a list of arrays.
Multi-dimensional array structures are created by using arrays of arrays (2-d structures), arrays of arrays of arrays (3-d structures) etc.

Example of a multidimensional array matrix:

Example of a multidimensional array matrix:

0,0 1,0 2,0
0,1 1,1 2,1
0,2 1,2 2,2
Syndicate content