Counting Backwards If you understand how forloops work,

September 30, 2006 on 8:39 am | In php |

Generating a Basic ArrayLook at the lines that describe $camelPop: //simply assign values to array$camelPop[1] = Somalia ; $camelPop[2] = Sudan ; $camelPop[3] = Mauritania ; $camelPop[4] = Pakistan ; $camelPop[5] = India ; The $camelPopvariable is a variable meant to hold the five countries with thelargest camel populations in the world. (If this array stuff isn t working for you, at least you ve learned something in this chapter!) Since $camelPopis going tohold the names of five different countries, it makes sense that this is an array(computer geek lingo for list) rather than an ordinary variable. The only thing different about $camelPopand all the other variables you veworked with so far is $camelPopcan have multiple values. To tell these valuesapart, use a numeric index in square brackets. Apparently the boxer George Foreman has several sons also named George. I veoften wondered what Mrs. Foreman does when she wants somebody to take outthe trash. I suspect she has assigned a number to each George, so there is noambiguity. This is exactly how arrays work. Each element has the same name, buta different numerical index so you can tell them apart. Many languages require you to explicitly create array variables, but PHP is veryeasygoing in this regard. Simply assign a value to a variable with an index insquare brackets and you ve created an array. Even though PHP is good natured about letting you create an array variable on- the-fly, you might get a warning about this behavior on those Web servers thathave error reporting set to E_ALL. If that s the case, you can create an empty arraywith the array()function described in the following sections and then add values to it. Using a Loop to Examine an Array s ContentsArrays go naturally with forloops. Very often when you have an array variable, you step through all of its values and do something to each one. In this example, I want to print the index and the corresponding country s name. Here s the forloop that performs this task: TRICKTRICK109Chapter
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services

WordPress database error: [Table './sandzak_com_-_blog/wp_comments' is marked as crashed and should be repaired]
SELECT * FROM wp_comments WHERE comment_post_ID = '190' AND comment_approved = '1' ORDER BY comment_date

No Comments yet

TrackBack URI

Sorry, the comment form is closed at this time.

Powered by cheap hosting