Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 









Oracle Database Tips by Donald Burleson


Unlike Perl, the arrays in PHP have no special notation. Array variables are marked prefixed with the dollar sign, not with the '@" or '%' as in Perl. Arrays are collections of a finite number of elements accessible either by their number or by a key. The following are two basic types of arrays:

  • $a=array("This","is", "an","array","of","strings");

  • $b=array("This"=>1,"is"=>2,"a"=>3,"hash"=>7);

The first way of defining the array makes it accessible through a numerical index.  The assignment $c=$a[1]; assigns the value of "is" to the variable $c. Assignment $c=$a[0]; assigns the value "This" to the variable $c.  Array $b, on the other hand, is defined as an array accessed through the textual key.  Such arrays are called associative arrays or hashes. Assignments such as $c=$b["hash"];  places the value 7 in the variable $c

Arrays in PHP can be multidimensional and are constructed from other arrays, just as matrices are constructed by putting rows together in a bigger whole. Below is a little script which constructs a 3x3 matrix $arr from arrays $a, $b and $c.

print $arr[2][1];

When executed, this script displays the letter "h" as a result. Array $arr is a matrix with 3 rows $a,$b and $c. Array indexes start with 0 so $arr[2][1] points to the second element of the third row, namely letter "h".

Arrays can also be empty.  The assignment $a=array(); assigns an empty array to variable $a. There is a note worthy difference between NULL and an empty array; an empty array can be populated, while NULL cannot.   The array constructor function "array" is not the only way to construct PHP arrays.  Arrays can be constructed simply by assigning values to their elements, as shown in the next example:


The array $a is so called a sparse array, which means that the indexes are not contiguous numbers. If the script below is executed by a web server, no errors are displayed and the result in browser is the expected one: 11||17

print $a[2]."|".$a[3]."|".$a[5];

If the same script is executed from the command line, an error revealing the undefined array offset 3 is displayed.

    $ php book1.php
    PHP Notice:  Undefined offset:  3 in
/home/mgogala/work/PHP/book1.php on line 7

Executing scripts from the command line is a good development practice which saves much effort and catches syntax errors. Errors marked as "Notice" or "Warning" will not terminate the script execution. Yet, errors marked as "Error" will.

So, how should sparse arrays be handled while trying to avoid the ugly errors such as the one above? The answer is to use iterator functionssimilar to those used in PL/SQL to deal with PL/SQL arrays.  Iterators can be thought of as smart indexes that remember position and know what the next value is. The following list presents the iterator functions along with a short definition of each:

  • Current($a) - This function returns the value of the current value of the array $a, with respect to the iterator.

  • Next($a)  - This function advances the iterator to the next position and sets the value of the iterator (returned by current()) to the new position.

  • Previous($a) - This function moves to the previous position and adjusts the value of the iterator.

  • End($a) - This function moves the iterator to the last value and adjusts the value of the iterator.

  • Reset($a) - This function returns the value of the iterator to the beginning of the array.

  • Key($a) - This function returns the current value of key for the hashes.

  • Each($a) - This function is used for loop control. It starts at the beginning, advances to the next value and returns FALSE after the last element effectively stopping the loop.

Detailed examples how to use iterators are presented in the next section following the introduction of loops.

PHP has many functions that operate on arrays and since this is not a PHP reference manual, no attempt to list every function will be made. The best source to learn about a particular function is through use of the PHP home page, located at

However, the sort function is worth special mention.  This function sorts the elements of the array. Many sort functions are used for different methods of comparison and sorting order (numeric sorting vs. string, ascending vs. descending, natural language sorting etc.) and all can be found on the same page of the online manual.

Another crucial difference between Perl and PHP must be mentioned. In Perl, it is perfectly legal to mix and match arrays and scalars such as in the following example:


Although this expression is legal in Perl, it is illegal in PHP. The presence of the array context is indicated by using the list function. If the variable $A is an array, the Perlish assignment above is written as the following:


Using array and list constructors is the paid price of not having to mark array variables in a special way to signify the array context.

At this point basic data types have been explained. Now, what to do with these data types are presented.

See code depot for complete scripts

This is an excerpt from the book Easy Oracle PHP.  You can get it for more than 30% by buying it directly from the publisher and get instant HTML-DB scripts from the code depot:

Easy Oracle PHP
Create Dynamic Web Pages with Oracle Data

Includes online HTML-DB code depot

Buy it now for 30% off - Only $19.95

HTML-DB support:

For HTML-DB development support just call to gat an Oracle Certified professional for all HTML-DB development projects.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.