PHP - Part 3 - Arrays

PHP - Part 3 - Arrays - CNT 4714: Enterprise Computing...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CNt 4714: PHP – Part 3 - Arrays Page 1 Dr. Mark Llewellyn © CNT 4714: Enterprise Computing Spring 2011 Introduction to PHP – Part 3 - Arrays Department of Electrical Engineering and Computer Science University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cnt4714/spr2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CNt 4714: PHP – Part 3 - Arrays Page 2 Dr. Mark Llewellyn © Arrays In PHP Most of our PHP examples to this point have involved scalar variables (we did see a couple of example in the first section of notes that made use of one of PHP’s global associative arrays). Scalar variables can only hold a single value at a time. For example, a variable $color could hold only a single value such as red , at any point in time. The variable could not be used to hold more than one color. Arrays are special types of variables that enable you to store as many values as you want. Note: Although you can technically make an array as large as you’d like, some built -in array handling functions in PHP have an upper limit of 100,000 values. If you are storing more data that this in your arrays and you need to use one of these functions, you will either need to write your own function or split the data into multiple arrays.
Background image of page 2
CNt 4714: PHP – Part 3 - Arrays Page 3 Dr. Mark Llewellyn © Arrays In PHP Arrays are indexed, which means that each entry in the array, called an element , is made up of a key and a value. The key is the index position, beginning with 0 and increasing incrementally by 1 with each new element in the array. The value is whatever value you associate with that position – a string, an integer, or whatever you want. In PHP you can think of an array as a filing cabinet and each key/value pair as a file folder. The key is the label written on the tab of the folder, and the value is what is inside. What’s inside each folder can vary from folder to folder.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PHP – Part 3 - Arrays Page 4 Dr. Mark Llewellyn © Creating Arrays In PHP You can create an array using either the array() function or the array operator [] . The array() function is usually used when you want to create a new array and populate it with more than one element, all at the same time. The array operator is more often used when you want to create a new array with just one element at the outset or when you want to add to an existing array element. The examples on the following couple of pages illustrate
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

PHP - Part 3 - Arrays - CNT 4714: Enterprise Computing...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online