Introduction to PHP.

Introduction to PHP.

Arrays.

Arrays in PHP are unlike those of any other common programming language

Best described as a melding of the arrays of C/Java with the hashes of Perl

The ultimate in flexible built-in data structures!!

Like a Perl hash, arrays in PHP have two parts: a key and a value

PHP arrays can have some elements with integer keys and some with string keys








<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
"http://www.w3.org/TR/xhtml1/dtd/xhtml1-strict.dtd">

                                                    
<!--	sorting.php
	An example to illustrate sorting functions
	-->

<html>
<head>
<title>
Sorting Functions
</title>
</head>

<body>
<?php
$original = array("Fred"=> 31, "Al" => 27, "Gandalf" => "wizzard",
		"Betty" => 42, "Frodo" => "hobbit" );
?>
<h4>Original Array</h4>
<?php
foreach ($original as $key => $value )
	print("[$key] => $value <br />");

$new = $original;
sort($new);
?>

<h4>Array Sorted by <tt>sort</tt></h4>
<?php
foreach ($new as $key => $value )
	print("[$key] => $value <br />");

$new = $original;
sort($new,  SORT_NUMERIC);
?>

<h4>Array Sorted by <tt>sort,  SORT_NUMERIC</tt></h4>
<?php
foreach ($new as $key => $value )
	print("[$key] => $value <br />");

$new = $original;
rsort($new);
?>

<h4>Array Sorted by <tt>rsort</tt></h4>
<?php
foreach ($new as $key => $value )
	print("[$key] => $value <br />");

$new = $original;
asort($new);
?>

<h4>Array Sorted by <tt>asort</tt></h4>
<?php
foreach ($new as $key => $value )
	print("[$key] => $value <br />");

$new = $original;
arsort($new);
?>

<h4>Array Sorted by <tt>arsort</tt></h4>
<?php
foreach ($new as $key => $value )
	print("[$key] => $value <br />");
?>
</body>
</html>

An example to illustrate sorting fucntions



| Origins and Uses of PHP | | Overview of PHP | | General Syntactic Characteristics |
| Primitives, Operations, and Expressions | | Output | | Control Statements |
| Arrays | | Functions | | Pattern Matching |
| Form Handling | | Files | | Cookies | | Session Tracking |