| Vamp the Linux LAMP through PHP part 2 |
|
| by David M Williams | |
| Monday, 01 October 2007 | |
|
Page 1 of 3 Last time we showed how anyone can get started writing, or reading, web pages coded with PHP, the “P” in “LAMP” (the rest being Linux, Apache and MySQL.) We received kind reader feedback that this was the friendliest and simplest PHP introduction they’d seen. What’s best of all is PHP is for everyone; even if you don’t run Linux, you can use PHP on the web space provided by your ISP.
Here’s how to prompt the user for information through standard HTML forms, and then have PHP act on these. Before we can get to that, though, it’s important to understand arrays.
Arrays There are two main benefits of using an array. The first is that you can use a loop to perform an operation on a whole bunch of data items with a very small amount of program code. This works by using another variable to act as an index into the array; each time through the loop increase the value of this variable. To act on a large set of individually named variables would be a more complex piece of program code, and would not easily lend itself to differing numbers of variables. Additionally – and this is something particularly nice about PHP – the index into an array doesn’t have to be an integer number; it could be a text string. This means it is dead simple to (for example) hold a count of the number of times different words are used in a sequence of text; all you need to do is have an array which is indexed by the actual word itself, and which simply holds an increasing count. Most other languages don’t have this flexibility and only allow arrays to be indexed by an integer. Here’s what some real code looks like which implements these concepts, including how to actually define an array: <?php
|
| < Next story in category | Previous story in the category > |
|---|

TAG 




