PHP Knowledge

  • what is PHP

  • What is PHP class
  • Smarty PHP
  • PHP Calendar

  • PHP delete
  • PHP count

  • PHP Directory
  • php echo
  • php exec
  • PHP explode
  • PHP fopen

  • PHP Form
  • PHP get

  • PHP If
  • PHP list
  • php login
  • PHP LOOP
  • PHP Random
  • PHP Redirect
  • PHP replace
  • PHP session
  • PHP sort
  • PHP split
  • php substr
  • PHP Syntax
  • PHP time

  • PHP upload
  • php URL
  • PHP version
  • PHP Cookie
  • PHP Global
  • php LDAP
  • PHP list
  • php strip
  • PHP template
  • php PEAR
  • PHP md5
  • PHP ini
  • PHP FTP
  • More others

    Javascript
    CSS
    PHP

     

    What is PHP class?


    What is PHP class?

    class

     

    A class is a collection of variables and functions working with these variables. A class is defined using the following syntax:

    <?php
    class Cart {
      var $items ;  // Items in our shopping cart

      // Add $num articles of $artnr to the cart

      function add_item ( $artnr , $num ) {
        $this -> items [ $artnr ] += $num ;
      }

      // Take $num articles of $artnr out of the cart

      function remove_item ( $artnr , $num ) {
        if ( $this -> items [ $artnr ] > $num ) {
          $this -> items [ $artnr ] -= $num ;
          return true ;
        } elseif ( $this -> items [ $artnr ] == $num ) {
          unset( $this -> items [ $artnr ]);
          return true ;
        } else {
          return false ;
        }
      }
    }
    ?>

    This defines a class named Cart that consists of an associative array of articles in the cart and two functions to add and remove items from this cart.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • Javascript |