PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

PHP Questions Forums : PHP Questions and Answers

Jump to Last Post

Tips on working with arrays in PHP

By: Timjohns [26-January-10 8:57AM]
25 posts
picture

It took me quite a while to understand arrays in PHP, so I thought this might be useful for some people who are new to PHP!

The key thing to remember with an array is that each element in the array has an index, or key, and then the value.

So if you have an array called $forexample then the first three items in that list by default would be referenced with:

$forexample[0];
$forexample[1];
$forexample[2];

... if the values of these were 3, 4, 5 respectively then echoing out those to the screen, e.g. echo "$forexample[0]"; would result in 3 being output to the screen.

There are also associative arrays, this is where the key is not numerical but could be, for instance, $person['last_name'] = "bobbins"; $person['height'] = 200; and so on.

That's the real basics but hopefully it might help someone!

Re : Tips on working with arrays in PHP


Petetimms [27-January-10 5:16PM]
11 posts
picture

Hi

Good tips there.

I also think it is well worthwhile getting to grips with the various functions for manipulating arrays.

Learning these save a lot of time down the line as there are functions that do most popular actions: for instance counting how many times a value appears in an array, reversing an array, flipping the keys and values, and of course the various sort functions too...

Next: Sending Text Messages With PHP



Custom Search