Posts

PHP function call of a another class within another class

################################ PHP CODE ################################ <?php // function call of a another class class class1 { function function1() { return 123; } function function2() { return 259; } } class class2 { function function1() { $object = new class1(); echo $object->function1()+$object->function2(); } } $obj = new class2(); $obj->function1(); // function call of a another class echo "<hr/>"; echo "Above Exapmle Basic : " . (123+259); echo "<hr/>"; ?> ################################ Output of the  CODE ################################ 382 Above Example Basic : 382

PHP Function definition within in a class

######################## PHP CODE ######################## <?php // function definition within in a class class common { function addition($a,$b) { echo "<br/> Sum of the " . $a . " and  " . $b . " is : " . ( $a + $b ) ; } function multiplication($a,$b) { echo "<br/> Multiplication of the " . $a . " and  " . $b . " is : " . ( $a * $b ) ; } } // function defination within in a class // object creation for class $com1 = new common(); // object creation for class // function call via class's object $com1->addition(2,3); $com1->multiplication(2,3); // function call via class's object ?>                    ########################                        OUTPUT of the CODE                     ######################## Sum of the 2 and 3 is : 5 Multiplication of the 2 a

Function definition with returning some value - PHP

############################ PHP Code ################### ######## <?php         // function definition with returning some value  function sum($a,$b)   {      $sum = $a + $b;   return $sum;  }  function minus($a,$b)  {    $minus = $a - $b;  return $minus;  }  // function definition with returning some value  // use of return function as a variable  echo "Sum of 2 and 3 is : ".sum(2,3);  // use of return function as a variable  // function definition with returning some value  ?> ############################ Output of the Code ############################ Sum of 2 and 3 is : 5

Function definition with returning array value - PHP

####################### PHP Code ####################### <?php function callmeforarray($a,$b) { $addition = $a + $b; $minus = $a - $b; $multiplication = $a * $b; $division = $a / $b; $modulus = $a % $b; $returnvalue['sum'] = $addition."<br/>"; $returnvalue['min'] = $minus."<br/>"; $returnvalue['mul'] = $multiplication."<br/>"; $returnvalue['div'] = $division."<br/>"; $returnvalue['mod'] = $modulus."<br/>"; return $returnvalue; } echo "<hr/>"; $result = callmeforarray(30,5); echo "Sum is : ". $result['sum']; echo "Min is : ". $result['min']; echo "mul is : ". $result['mul']; echo "div is : ". $result['div']; echo "mod is : ". $result['mo

PHP Function call - Just running the code within it

############################ PHP Code ############################ Program 01:      Normal Function just running the code within it <?php    //  Normal Function just running the code within it    //  function definition  function callme($a,$b)   {     // echo "<br/>Sum of the ".$a." and ".$b. "is = ".$a+$b;       echo "<br/>Sum of the ".$a." and ".$b. "is = ".($a+$b);       echo "<br/>Multi of the ".$a." and ".$b. "is = ".$a*$b;       echo "<br/>Min of the ".$a." and ".$b. "is = ".$a-$b;       echo "<br/>Divide of the ".$a." and ".$b. "is = ".$a/$b;       echo "<br/>Modulus of the ".$a." and ".$b. "is = ".$a%$b;     }    // function defination     // function call      callme(2,5);     // function call ?> ############################ Ou

Basic for Function on PHP

Function:        Function are a set of bloch, which are defined for calling a set of code again and again. There are two way to calling a function in PHP: Directly calling a Function. Function called by a object of a class and defined within a class.  They are Important as some of the code, we have to use different location on a site. So a good way is to define in a File i.e. "functions.php" and include it to top of the position. ############################ PHP Code ############################ Program 01:      Normal Function just running the code within it <?php //  Normal Function just running the code within it //  function definition function callme($a,$b) { // echo "<br/>Sum of the ".$a." and ".$b. "is = ".$a+$b; echo "<br/>Sum of the ".$a." and ".$b. "is = ".($a+$b); echo "<br/>Multi of the ".$a." and ".$b. "

Type of the Variable

Here we will understand, How we can know the type of the variable. As PHP automatic set the type to the variable as we defined it, But sometime it is neccessary to check the type of the variable. Suppose you have a condition, that it there is more then 10 Items in store,  you will add them all for calculation of the total payment, but when  the item is only one, there is no need to adding them, as the total cost will be cost of the item. So you can do by checking the variable type of the variable m If it is array then we will add them all, if this is only a string or Integer, and it is the final cost. Example you have an Variable $value. if it is array, we will use array function to check as follow: <?php                                $totalcost = 0;    if( is_array ($value) )               {                    foreach ( $value as $single )                       {                              $totalcost = $totalcost + $value;