WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Permutations, Combinations and Factorials
Categories : PHP, PHP Classes, Math. Click here to Update Your Picture
leaping langoor
Date : Apr 27th 2005
Grade : 2 of 5 (graded 4 times)
Viewed : 14300
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
/********************************************************
** Permutations, Combinations and Factorials
**
** Author.: leapinglangoor [ leapinglangoor@yahoo.co.in ]
** Date...: 12th feb 2005
** Version: v1.2
**
** Desc...: Permutations and combinations are a major part
**          of maths and here it is in PHP
**
********************************************************/
class maths
{

    function
fact( $num )
    {

       
$res = 1;

        for (
$i = 2; $i <= $num; $i++)
        {
           
$res *= $i;
        }

        return
$res;
    }


    function
perms( $n, $r )
    {

        if(
$r > $n )
        {
            return
0;
        }

       
$i = 0;
       
$res = 1;
        while(
$i < $r )
        {
           
$res = $res * $n;
           
$i++;
           
$n--;
        }


        return
$res;
    }

    function
combos( $n, $r )
    {

        if(
$r > $n )
        {
            return
0;
        }

       
$res = perms( $n, $r );
       
$res = $res / fact( $r );

        return
$res;
    }

}
// End class math

?>


example1.php:
<?php

include( 'math.php' );

$maths = new maths;

$n = 5;
$r = 3;

$n = 5;
$r = 3;

$maths->fact( $n ); // Factorial of $n
echo $m->fact( $n ); // returns 120

$maths->perms( $n, $r ); // Permutations of $n taking $r things at a time.
echo $m->perms( $n, $r ); // returns 60

$maths->combos( $n, $r ); // Combinations of $n taking $r things at a time.
echo $m->cobos( $n, $r ); // returns 10
?>



Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP, PHP Classes, Math.
3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs
.htpassword manager for apache
Categories : PHP, PHP Classes, Authentication, Apache
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
Blueshoes PHP Application Framework
Categories : PHP, Frameworks, PHP Classes
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
Power Form Validation
Categories : PHP, PHP Classes, Data Validation
Class to convert any document, that can be read by MS Word, to another format supported by Word.
Categories : PHP Classes, PHP, Windows 2000, Microsoft Word, WinNT
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Calculator for Baroque Violin strings
Categories : Math., PHP, Strings
Sample usage of IPv6 and IPv4 with PHP
Categories : PHP, PHP Classes, Network
SPL and ITERATOR : examples
Categories : PHP, Object Oriented, PHP Classes, Sessions
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
 paulz leex wrote : 1321
can not run, with error :
Warning: Unterminated comment starting line 3 in C:\Program Files\Apache Group\Apache2\htdocs\per2.php on line 3
 
 leapinglangoor wrote : 1322
uhmmmm... Is it just me, or is the example showing only "&lt;?php" - somebody`s gotto really look into this!!!
 
 Boaz Yahav wrote :1323
fixed :)