Elements of the enumerated array are numbers

Saturday, August 1st, 2009

 <?php
  $sortnumbers []= 10000;
  $sortnumbers []= 10;
  $sortnumbers []= 100;
  $sortnumbers []= 1000;
  $sortnumbers []= 1;

  sort ($sortnumbers);

  foreach ($sortnumbers as $val) {
    echo "$val", "\n";
  }
 ?>

           
       

in_array

Friday, July 24th, 2009

<?php
class Person {
    private $name;    
    private $age;    
    private $id;    

    function __construct( $name, $age ) {
        $this->name = $name;
        $this->age = $age;
    }

    function setId( $id ) {
        $this->id = $id;
    }
    
    function getId(){
        echo "get id method";    
    }
    
    function __clone() {
        $this->id = 0;
    }
}
$p = new Person("A",10);

$method = "getId";     // define a method name

if ( in_array( $method, get_class_methods( $p ) ) ) {
    print $p->$method();  // invoke the method
}

?>

           
       

String token: space

Wednesday, July 22nd, 2009

<?
$token = strtok("open-source HTML-embedded server-side Web scripting"," ");
while($token){
  print($token . "<BR>");
  $token = strtok(" ");
}

?>
      
           
       

Number format function prototype

Wednesday, July 22nd, 2009

<?
string number_format(float number, int decimals, string dec_point, string
    thousands_sep)

?>

Argument        Description

number          Number to be formatted

decimals        Precision: number of decimal places 

dec_point       String used for the decimal point (in North America, usually a period)

thousands_sep   String to separate groups of thousands (in North America, usually a comma)

           
       

Use md5 function to encrypt text

Sunday, July 19th, 2009

<?php
   $val = "secret";
   echo "Pre-hash string: $val <br />";
   $hash_val = md5 ($val);
   echo "Hashed outcome: $hash_val";
?>