2. Overivew
Objective
For beginners to learn the basics of PHP. PHP is required
for using ProdigyView.
Requirements
Willingness To Learn
General knowledge of programming
Estimated Time
10 minutes
http://www.prodigyview.com
3. Follow Along With A Code
Example
1. Download a copy of the example code at
www.prodigyview.com/source.
2. Install the system in an environment you feel
comfortable testing in.
3. Proceed to examples/basics/PHP_Basics_2.php
http://www.prodigyview.com
5. Welcome
Before you start using ProdigyView, you need to have
some of the basics down in PHP. This tutorial is for
people who have some programming experience but are
relatively new to programming in PHP.
This tutorial is no where covers everything but will
hopefully cover enough to get you started on the learning
process.
You will need to play around with the code to get a good
understanding of these concepts.
http://www.prodigyview.com
6. VariablesDepending on if you have
The best place to start in PHP is with variables.
used other languages like Java, C++, Objective-C you will likely be use to
defining a variable by giving it a type, name and a value.
Examples:
int anumber = 1;
boolean opened = true;
String[] mystrings = new String[15];
In PHP it is a little simpler. All have to do is assign a value to a variable.
Variables start with the dollar($) sign and are case sensitive. After the dollar
sign, variables can either start with a letter or underscore, followed by any
combination of letters, underscore or numbers.
The equal sign sets the value of the variables
7. DEFINES
Defines are variables that are made global. This means
that the variable can be accessed anywhere in the
code, including functions and in objects.
Following PHP coding standards, when setting a
define, they should always be capitalized.
Once a define is set, it cannot be changed.
1. Name of the Define 2. Value assigned to the define
8. Variables Can Be Anything
Variables are not only values such as integers and strings
but can also be object and arrays. In an more advanced
tutorial we will set variables to be structures such as
anonymous functions. But for now, understand that a
variable can be anything.
http://www.prodigyview.com
9. Arrays
So now that we have variables down, we can move on to
arrays. Arrays are a collection of variables. If you use
arrays in other languages then you might be use to setting
an array size or setting the index of an array as a numeric
value. In PHP you do not have to set the array size and
an index can be either a string or integer.
1. Explicitly set the index of an array
2. The array() function creates an array whose index can be assigned
10. Iterating Arrays
After you get use to creating arrays, the next step is
iterating through them. Iterating through an array will allow
you to get the values entered into the array. Also arrays
can be combined to create a new array with the values of
both array.
Key is the index and value is value of the index
Add two arrays to create a new array
11. Functions
Next stop, the function in PHP. Functions is code that can
be executed when called. Functions contain variables and
variables can passed to functions. When functions are
defined outside of a class, they can be called anywhere in
your code.
1. Define Function 2. Represents values to be passed to the function
4.Call/Execute Function 3. Returns a value to the location the function was called
12. Objects
We’ve covered variables, arrays and functions. All of
those attributes can go inside of an object. Objects are
defined by a ‘class’. When a function is inside an class, it
is then referred to as a method.
Inside an class, the attributes can have three states:
public, private and protected. We will get more into this in
another tutorial.
Like other languages, object can be initialized or
instantiated(able to be accessed) with the keyword ‘new’.
http://www.prodigyview.com
13. Object Example
1. Define the Class
2. Create method within class
4. Call method 3. Instantiate Object
14. Challenge!
Now we should have some basic understanding of PHP.
To better understand variables, functions and objects,
complete this challenge. Keep in mind there is no right
answer.
Create an object that had methods for adding,
subtracting, multiplying and dividing numbers. Store the
return results in an array and iterate through that array.
http://www.prodigyview.com
15. The Not So Obvious
1. Using ‘echo’ or ‘print’ will print/display the value of a
variable to the user.
2. The ‘return’ in a function will return a value to the
place the function was called.
3. Using ‘//’ will allow you to leave comments in the code.
Comments are ignored by the compiler and will not
affect your code.
4. To call a method in an object, use the ->. The arrow
should point to the name of the method.
Example: $object->methodName()
http://www.prodigyview.com
16. Review
1. Variables can be anything: Arrays, Objects, String,
Booleans, Integers, etc
2. Array are data structures that hold multiple variables
3. Functions is code that completes a task and can be called
from anywhere in execution
4. Functions inside an object is called a method and can only
be accessed through that object
5. Objects are data structures that contain functions and
variables.
6. Defines are non-mutable variables that are accessible
anywhere in the code execution.
http://www.prodigyview.com
17. More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials
www.prodigyview.com