IT.COM

Introduction to PHP Arrays

Spaceship Spaceship
Watch

itnashvillecom

Account Closed
Impact
1
Let's say that you want to store numerous values within one variable. It may sound complex for some of you, but to those of us that use arrays daily, they are a God send. They help us to unclutter and organize our code and speed up development.

How to create an array:

PHP:
$cars = array(1 => "Chevy", 2=> "Honda", 3=> "Mitsubishi");


Now you can use this array.

PHP:
$cars = array(1 => "Chevy", 2=> "Honda", 3=> "Mitsubishi");
if ($_POST['favorite'] == 2) {
     $favorite_car = $cars[2];
     echo 'Your favorite make of car is '.$favorite_car;
}

This will print:

Your favorite make of car is Honda

*Note: Do not use quotes in the array when using the numeric key. $cars['2'] is bad. However, you can use $cars['Honda'].
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
0
•••
Yes indeed. I am partial to recommending PHP5 for Dummies. It is very thorough and within 30 days you can be coding excellent scripts.
 
0
•••
yeah better catching the latest
itnashvillecom said:
Yes indeed. I am partial to recommending PHP5 for Dummies. It is very thorough and within 30 days you can be coding excellent scripts.
 
0
•••
I prefer php.net or How to Do Everything with PHP and MySQL and if your looking for something for absolute beginners you could Php Phrasebook Essential Code and you could get some of these ebooks at http://betah.co.il/ you could find more if you search here. I hope you find this helpful
 
0
•••
Honestly, my belief is that if you really need to buy books to learn a programming language, you're probably not cut out to be a web designer.
Books are great, they spoon feed you everything piece by piece.

However, in my opinion, there is So much information online that anyone who really has the passion to learn would just use php.net, w3schools, etc.
And if you don't have the passion, go be a used car salesman or something.


Bruce
 
0
•••
yes i know. get all your hands on everything you can get to learn.
can't do away with books.
btw programming is entirely different from web design.
my books are my reference, they are very handy to me while the internet is down esp. in our country. every 4 hours down :lol:

Bruce_KD said:
Honestly, my belief is that if you really need to buy books to learn a programming language, you're probably not cut out to be a web designer.
Books are great, they spoon feed you everything piece by piece.

However, in my opinion, there is So much information online that anyone who really has the passion to learn would just use php.net, w3schools, etc.
And if you don't have the passion, go be a used car salesman or something.


Bruce
 
0
•••
Bruce_KD said:
Honestly, my belief is that if you really need to buy books to learn a programming language, you're probably not cut out to be a web designer.
Books are great, they spoon feed you everything piece by piece.

However, in my opinion, there is So much information online that anyone who really has the passion to learn would just use php.net, w3schools, etc.
And if you don't have the passion, go be a used car salesman or something.


Bruce
I was talking about a programmer/developer, and if you think people learning from books aren't cut out to be web designers well i don't agree most people learn from books, and even most of the information on the internet related to web designing is from books.
 
0
•••
Learning on the web, people tend to have holes in their education. If you were correct, then we would not have evolved past the point seeing the world as flat. The most efficient manner is to learn thoroughly the basics, and then work up by experimentation and further study.

And if you don't have the passion, go be a used car salesman or something.

I would hire a person with an education via theory and practice over just practice any day. I want a person that truly understands WHY to do something, not just that it can be done.
 
Last edited:
0
•••
itnashvillecom said:
Learning on the web, people tend to have holes in their education. If you were correct, then we would not have evolved past the point seeing the world as flat. The most efficient manner is to learn thoroughly the basics, and then work up by experimentation and further study.
true
 
0
•••
itnashvillecom said:
*Note: Do not use quotes in the array when using the numeric key. $cars['2'] is bad. However, you can use $cars['Honda'].

Don't forget to teach them how to use the numbers :P

$cars[2] will output the information in 2 in the array. :)

-RageD
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back