News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

PHP Lesson 03 - variable/array/function definitions

Started by Parham, August 26, 2003, 11:24:18 PM

Previous topic - Next topic

Parham

This lesson I thought I would get a little technical (without getting TOO technical) with definitions of a few words you'll coming across regularly in these lessons.

What is a variable?
A variable is something that can hold a dynamic value.  You can think of a variable as a box and its contents as the variables value.  The stuff inside the box can be changed; stuff taken out and replaced by other stuff.  This is exactly how you should think of a variable, as something which can always change to your needs.  A variable has two parts, a name and a value.

What is an array?
An array is something that can hold several dynamic values.  Very much like a variable, think of an array as a BIG box which can hold several similar objects.  The stuff inside this big box can be changed; stuff taken out and replaced with other stuff or more stuff can be added to this big box.  If that's a little hard to picture, think of an array as simply a list of values where more values can be added or existing values can be modified or removed.  An array has two parts, a name and a value.

What is a function?
A function is exactly what its dictionary definition says: The action for which a person or thing is particularly fitted or employed.  A function is a set of code which does a particular task.  A function has three parts, a name, information you give it, and information it returns.

Those of you who are very eager to explore the PHP language should get yourselves familiar with the PHP documentation and API located at http://www.php.net/manual/en/.  This is the website where you can find all of PHP's built-in functions and features.  The site will also help you with basic syntax.  The great thing about using the online documentation at PHP's website is that there is a wealth of user comments for everything to help clear up misunderstandings you might have.

A few things you might want to read up on for the next lesson would be the following two sites:
http://www.php.net/manual/en/function.print.php
and
http://www.php.net/manual/en/function.echo.php

Parham

I'd really appreciate people posting so I'd get a nice feel for how many people are actually reading these (and liking them).  I know they're not exactly top-notch lessons which is why I'm hoping to get the other members to post followup explanations or clarifications.

Chris Cromer

An array has 3 parts, a name, and keys, and then the values in those keys. ;)

Very nice work on these tutorials, I am sure they will help alot of newbs... although I doubt there will be anything beneficial to me... although I guess you learn something new everyday. :)
Chris Cromer

"I was here, here I was, was I here, sure I was" - The little voice in my head.

[Unknown]

#3
For Visual People...

I always like to think of an array... like this...

You have a large box with lots of things in it.  Each thing has a tag on it, with a name or number.  These "tags" are called keys.
The thing itself, which could even be another box, is the "value".

Then you have "scalar" variables. (basically, not an array... usually just called variables, although arrays are "variables" too.)  They are just like cards.  They have tags to - as do the boxes (arrays) - and these tags are their names.

Finding one of these cards is really quite easy.  You just put a dollar sign ($) and then the name - like this: $my_really_cool_card. (note that they can only be named with certain letters.)



For Technical People:

An array is like a inventory list.  Kinda like this:
Key               Value
---------------------------
0                 567
1                 657
2                 fdsf
A                 myvalue
name              John


A variable is just like a name for something that stores numbers for you.  Kinda like in math, except with longer names.

Unlike in math, you have to use a $ sign and then the name to refer to it.



-[Unknown]

Shadow's Pawn

I know a bit of php but I'm reading through your tuts and doing the stuff in them anyway..  I'm sure I'll end up learning a lot I don't know.

zoki

Sure, it's always nice to see some nice tutorials. I'm sure both newbies and experienced programmers will learn from these nice, small tuts.

Crush

These Tutorials are Great! I went through lesson 1 and got my big E with a flashing red dot going and got excited after verified they are working!
That is how much of a newbie at php I am!
My goal is to edit the look of the SMF board which I just installed, hopefully these tutorials will help me out!

Thanks!!

NeonXL

Now it´s 2007, but this tutorial still works for me!

Thanks a lot, Parham. Great work!

Advertisement: