Advertisement:

Author Topic: PHP Lesson 03 - variable/array/function definitions  (Read 25292 times)

Offline Parham

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,317
  • Gender: Male
  • #!/usr/bin/perl
    • Online Node
PHP Lesson 03 - variable/array/function definitions
« on: August 26, 2003, 11:24:18 PM »
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
« Last Edit: March 29, 2004, 05:03:46 AM by [Unknown] »

Offline Parham

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,317
  • Gender: Male
  • #!/usr/bin/perl
    • Online Node
Re:PHP Lesson 3
« Reply #1 on: August 26, 2003, 11:25:55 PM »
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.

Offline Chris Cromer

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,745
  • Gender: Male
  • I am just a figment of your imagination!
    • Chris's AGI Web Site
Re:PHP Lesson 3
« Reply #2 on: August 27, 2003, 12:06:36 AM »
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.

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re:PHP Lesson 3
« Reply #3 on: August 27, 2003, 12:47:06 AM »
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]
« Last Edit: August 27, 2003, 12:48:55 AM by [Unknown] »

Offline Shadow's Pawn

  • Semi-Newbie
  • *
  • Posts: 64
  • Gender: Male
  • ich soll nicht toten
    • Centre For the Arts
Re:PHP Lesson 3
« Reply #4 on: August 27, 2003, 11:57:02 AM »
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.

Offline zoki

  • Semi-Newbie
  • *
  • Posts: 43
  • Gender: Male
  • Have you seen me offline?
Re: PHP Lesson 3 - variable/array/function definitions
« Reply #5 on: November 07, 2003, 06:34:47 PM »
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.

Offline Crush

  • Semi-Newbie
  • *
  • Posts: 14
Re: PHP Lesson 03 - variable/array/function definitions
« Reply #6 on: May 06, 2004, 08:10:14 PM »
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!!

Offline NeonXL

  • Semi-Newbie
  • *
  • Posts: 11
  • Gender: Male
    • Platform independent Programming with Revolution (German)
Re: PHP Lesson 03 - variable/array/function definitions
« Reply #7 on: June 09, 2007, 04:38:07 PM »
Now it´s 2007, but this tutorial still works for me!

Thanks a lot, Parham. Great work!