Basic PHP 1

Views:
 
     
 

Presentation Description

A quick tutorial on the basics of PHP

Comments

Presentation Transcript

PHP Basic Part 1:

PHP Basic Part 1

Overivew:

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

Follow Along With A Code Example:

Follow Along With A Code Example Download a copy of the example code at www.prodigyview.com/source . Install the system in an environment you feel comfortable testing in. Proceed to examples /basics/ PHP_Basics.php http:// www.prodigyview.com

Concepts To Cover:

Concepts To Cover Variables Arrays Defines Functions Objects Challenge! Review http:// www.prodigyview.com

Welcome:

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

Variables:

Variables The best place to start in PHP is with variables. Depending on if you have 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: i nt 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

DEFINES:

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. Name of the Define Value assigned to the define

Variables Can Be Anything:

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

Arrays:

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. Explicitly set the index of an array The array() function creates an array whose index can be assigned

Iterating Arrays:

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. Add two arrays to create a new array Key is the index and value is value of the index

Functions:

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. Call/Execute Function Define Function Represents values to be passed to the function Returns a value to the location the function was called

Objects:

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

Object Example:

Object Example Call method Instantiate Object Create method within class Define the Class

Challenge!:

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

The Not So Obvious:

The Not So Obvious Using ‘echo’ or ‘print’ will print/display the value of a variable to the user. The ‘return’ in a function will return a value to the place the function was called. Using ‘//’ will allow you to leave comments in the code. Comments are ignored by the compiler and will not affect your code. 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

Review:

Review Variables can be anything: Arrays, Objects, String, Booleans, Integers, etc Array are data structures that hold multiple variables Functions is code that completes a task and can be called from anywhere in execution Functions inside an object is called a method and can only be accessed through that object Objects are data structures that contain functions and variables. Defines are non-mutable variables that are accessible anywhere in the code execution. http:// www.prodigyview.com

authorStream Live Help