Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
An Overview of Arrays in PHP

An Overview of Arrays in PHP



|Views: 364|Likes:
Published by Cristian Ciofu
In this article I will explain arrays and how they are used in PHP.
In this article I will explain arrays and how they are used in PHP.

More info:

Published by: Cristian Ciofu on Jun 28, 2007
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Page 1http://codewalkers.com/tutorials/8/1.html
An Overview of Arrays inPHP
by Matt Wade
In this article I will explain arrays and how they are used in PHP.
An Overview of Arrays in PHPby Matt Wade
Page 2http://codewalkers.com/tutorials/8/1.html
Arrays in PHP
The PHP Manual defines an array in PHP as an ordered map. Personally, I don't likethis definition. I will define an array in PHP as a collection of variables, which I think is alittle more descriptive. In most languages, atleast the ones I am familar with, thevariables in this collection must all be of the same type. Not so in PHP! This is becauseof PHP's (http://www.php.net/manual/fi/html/language.types.type-juggling.html) TypeJuggling. I'm not going to go into great detail about Type Juggling, but basically itmeans that you don't declare a variable as a certain type. The context in which thevariable is used determines its type.So, how do you assign values to arrays? The exact same way as you would any othervariable, except that you specify which element of the array you wish to work with. Oneimportant thing to note is that, by default, arrays start numbering their elements at zero.Check this out:
<?php$array[0] =3; $array[1] =6; $array[2] =2; ?>
A cool feature of PHP is the ability to use associative arrays. Associative arrays giveyou the ability to name your array's keys. So, instead of having $array[0] and $array[1]you can have $array['something'] and $array['anotherthing'].So what's the big deal? Why would I want to use arrays rather than just regular oldvariables? Imagine this: You are working with customer's names. You have 5 of themthat you continually need to echo out. With regular variables, you would do it like this:
<?phpecho"$customer1<BR>\n"; echo"$customer2<BR>\n"; echo"$customer3<BR>\n"; echo"$customer4<BR>\n"; echo"$customer5<BR>\n"; ?>
Pretty long winded. Imagine doing that with 100 customers. Or 1000. With arrays, youcan use a foreach loop. What a foreach loop does is loop as many times as you haveelements in an array. Suppose you had an array called $customer that contained yourcustomer names. Check this out:

Activity (10)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Dan liked this
muniiera liked this
Kunalkishor Singh liked this
Kunalkishor Singh liked this
Sheila Ann Medrano liked this
Sheila Ann Medrano liked this
spamcaliph6002 liked this
suchi9 liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->