|
|
|
Home Credits Affliates Link Exchange HTMLshaman PHPshaman LINUXshaman Helpful Links Web Design Images Backgrounds Icon Sets GIF Images |
Language Intro : Arrays An Array is like a shelf with columns that stoes things in a specific order from 1 to the number you want it to end. PHP will automatically place an array number or index number everytime you place something into the array. Lets start working with hardcoded variables. Example : $mashmellow[] = "Sweet"; $mashmellow[] = "Over Cooked"; $mashmellow[] = "Deep Fried"; $mashmellow[500] = "RAW"; Those that are without an index number will be placed in sequence, 1 for "Sweet", 2 for "Over Cooked" and so on. however if you place a number in the [] you will manually assign it to a specific location. In the above example, its 500. Now what happens if we issue a print or an echo command? Example : print $mashmellow[3]; The above gaves us "Deep Fried". There are however many ways you can define an array and a good method would be as follows : Example : $mashcontainer = "mash1, mash2, mash3, mash4"; $mashmellow = array ( $mashcontainer ); This will produce that $mashmellow is the Array and $mashcontainer will become the stored values, allowing us to place values into the Array. And if you call to print or echo the array $mashmellow[3], you will get the response "mash3". We can also get the above to print all values in the Array with a foreach command. Example with the recent example : $mashcontainer = "mash1, mash2, mash3, mash4"; $mashmellow = array ( $mashcontainer ); foreach ( $mashmellow as $masharray ) { print "$masharray is actually just another mashmellow.<br>" } What happens here is that it takes each and every value in the Array and then outputs it and added the "is actually just another mashmellow.<br>" line to it. Tt will display as follows : mash1 is actually just another mashmellow. mash2 is actually just another mashmellow. mash3 is actually just another mashmellow. mash4 is actually just another mashmellow. There are many other ways in which you can work with arrays like merging ( array_merge() ), removing ( array_shift() ) and so on, we will leave you to explore the possibilities as you progress in your own coding experience.
|
| Our Recommended Links |
|
|
Contact us at webmaster@galacnet.com for advertising opportunities on GalacNet. |