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!


Related Articles

  • Introduction to Javascript for Newbies
    Javascript is a client-side programming language whose processing engine is embedded in web browsers like Internet Explorer, Netscape, Firefox, etc. This enables the processing engine to read and interpret web pages that contain the javascript code when browsing
  • Object Oriented Programming With PHP 4.1.x
    Object Oriented Programming provides raw power to PHP 4.1.x Part 1:Introduction First off, an object (also know as a class) is a very simple section of code that has a section of its own variables and functions. In a simple way an object is kind of like a program itself. Objects can be used fo...
  • XHTML vs. HTML
    A quick introduction to XHTML
  • 4 Powerful Features of Javascript Programming Language
    In the community of web developers and surfers, Javascript is highly popular as client side scripting language for web browsers. Lets take a look at some of the features of this language.
  • PHP Introduction
    A short and simple introduction to
  • Object Orient Programming: Image Class
    This tutorial is a Web Programming in PHP article on Object Orient Programming: Image Class. The author says, I share the code I use for my image class. Four functions: Upload, Resize, Get a file extenstion, Resize on the fly.
  • Drive Traffic To Your Website With This Little Known Method
    One of the methods that has spawned many success stories in driving traffic into websites is viral marketing. This article will tell in details about this method.
  • Getting professional website - a cheap and easy way
    Express yourself to the world with a dazzling website having professonal combination of color and images with an opening animation. Get your own URL in web and show it up to the rest of the world...
  • Introduction to Serializing
    Also includes an example that you can use to start building apps with serialize.
  • NT or UNIX? TopHosts helps you decide!
    When planning an Internet venture, one of the most basic questions for any Webmaster is what platform to base the Web site on. The two most popular platforms, UNIX and NT are widely available and offer various options and have differing abilities. Your choice of platform will define the utility and ...

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.