PHP Language Basics

Variables and Expressions

<?php
    $foo = 1;
    $bar = "Testing";
    $xyz = 3.14;
    $foo = $foo + 1;
?>

Arrays

<?php
    $foo[1] = 1;  
    $foo[2] = 2;
    $bar[1][2] = 3;
?>

Functions

<?php
    $phpinfo = phpinfo();
    $name = is_array($phpinfo);
    $len = strlen($foo);
?>

Control Structures

<?php

    // If statement
    if($foo) {
        // Do your work here
    }


    // If else statement
    if($foo) {
        // Do your work here
    } else {
        // Dp your false work here.
    }


    // For loop
    for($i = 0; $i <= 5; $i++ ) {
        // Repeat your work for 6 time, remember, loop starting from 0 and ends at 5.
    }


    // While loop
    while($foo) {
        // While Statement here
    }


    // Foreach Loop
    foreach($arrayVariable as $singleValue) {
        echo $singleValue;
    }


    // Or Foreach Loop
    foreach($arrayVaraible as $singleKey => $singleValue) {
        echo 'Key : '.$singleKey.' with Value : '.$singleValue;
    }


?>

Output

<?php

    echo 'My Name is John Doe';

    $price = 97.9876;

    printf(".2f",$price);

    echo $price;

?>

 

 

Loading ...

Related Results :

  1. PHP Language Basics
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author