PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Introduction to Procedural Programming
Your Ad Here

Introduction to Procedural Programming


Introduction to Procedural ProgrammingWe'll start of with if

Here is the basic usage of it

<?php
    if (variable CONDITION value) {
        //the condition was met
    }
?>

variable would be something like $variable

CONDITION can be something like == (equal to) or <= (less than or equal to)

value can be 10 or 20, doesn't matter

So we'll do this

<?php
    if ($variable == 10) {
        //$variable does equal 10
    }
?>

Now we'll add an ELSE statement to the mix

<?php
    if ($variable == 10) {
        //$variable does equal 10
    } else {
        //$variable does NOT equal 10
    }
?>

Pretty straight forward, let's try an ELSEIF statement

<?php
    if ($variable == 10) {
        //$variable does equal 10
    } elseif ($variable == 20) {
        //$variable does NOT equal 10, but it DOES equal 20
    }
?>

A bit confusing at first, but I'm sure you'll get the jist of it

Aside from if statements, there are switch statements

<?php
    switch ($variable) {
        case 'one':
            //$variable equals one
        break;
        case 'two':
            //$variable equals two
        break;
        default:
            //$variable does NOT equal one or two
        break;
    }
?>

So if $variable equals one, then it would trigger the first bit, if it didn't equal one or two, it would trigger DEFAULT, which is like the ELSE statement for IF's

That's it for the tutorial, after you get comfortable with procedural programming, be sure to checkout object orientated programming tutorials!



Author's URL: GreyCobra.com
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Introduction to Procedural Programming"

Only registered users can write comment

Reader's comments