google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Friday, October 23, 2015

php notes

Special data type in php
 Null is a special data type which can have only one value: NULL.
A variable of data type NULL is a variable that has no value assigned to it.
Ex:-
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
Output:- NULL



Abstract class in php:-
1. PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method's signature - they cannot define the implementation.
2. When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility.
3. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private. Furthermore the signatures of the methods must match, i.e. the type hints and the number of required arguments must be the same.
4. For example, if the child class defines an optional argument, where the abstract method's signature does not, there is no conflict in the signature. This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures could differ.
Abstract example:-
<?php
abstract class AbstractClass
{
    // Our abstract method only needs to define the required arguments
    abstract protected function prefixName($name);

}

class ConcreteClass extends AbstractClass
{

    // Our child class may define optional arguments not in the parent's signature
    public function prefixName($name, $separator = ".") {
        if ($name == "Pacman") {
            $prefix = "Mr";
        } elseif ($name == "Pacwoman") {
            $prefix = "Mrs";
        } else {
            $prefix = "";
        }
        return "{$prefix}{$separator} {$name}";
    }
}

$class = new ConcreteClass;
echo $class->prefixName("Pacman"), "\n";
echo $class->prefixName("Pacwoman"), "\n";
?>
The above example will output:
Mr. Pacman
Mrs. Pacwoman


COOKIE IN PHP:
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Purpose of cookie:-
Cookies make the interaction between users and web sites faster and easier. Without cookies, it would be very difficult for a web site to allow a visitor to fill up a shopping cart or to remember the user's preferences or registration details for a future visit.

Web sites use cookies mainly because they save time and make the browsing experience more efficient and enjoyable. Web sites often use cookies for the purposes of collecting demographic information about their users.

Cookies enable web sites to monitor their users' web surfing habits and profile them for marketing purposes (for example, to find out which products or services they are interested in and send them targeted advertisements).
 In php :-
1. PHP transparently supports HTTP cookies.
2. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users.
3. We can set cookies using the setcookie() or setrawcookie() function.
4. Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the browser. This is the same limitation that header() has
5. We can use the output buffering functions to delay the script output until you have decided whether or not to set any cookies or send any headers.
6. Any cookies sent to you from the client will automatically be included into a $_COOKIE auto-global array if variables_order contains "C". To assign multiple values to a single cookie, just add [ ] to the cookie name.
7. Depending on register_globals, regular PHP variables can be created from cookies. However it's not recommended to rely on them as this feature is often turned off for the sake of security
Setting new cookie:-
<?php
setcookie("name","value",time()+$int);
/*name is your cookie's name
value is cookie's value
$int is time of cookie expires*/
?>
Getting Cookie:-
<?php
echo $_COOKIE["your cookie name"];
?>
Updating Cookie:-
<?php
setcookie("color","red");
echo $_COOKIE["color"];
/*color is red*/
/* your codes and functions*/
setcookie("color","blue");
echo $_COOKIE["color"];
/*new color is blue*/
?>
Deleting Cookie:-
<?php
unset($_COOKIE["yourcookie"]);
/*Or*/
setcookie("yourcookie","yourvalue",time()-1);
/*it expired so it's deleted*/
?>.


Tuesday, April 28, 2015

To solve multiplication of numbers in few seconds

Example 1
Calculate 98 * 93
Solution
Select a closest base ( a power of 10). In this case we can select 100 as a base. Write these numbers with the difference from the base. That is 98-100 = -2 and 93-100 is -7. So write it as
98   :   -2
93   :   -7
Left side of the answer will be the diagonal sum including their signs. That is 98-7=91. So 91 will be the left side of the product. (You can take the other diagonal sum also, that is 93-2=91. Always these diagonal sums will be same).
To find the right hand side, just multiply the differences including their signs. That is -2 * -7 = 14
So we got that left side of the product is 91 and right side is 14. So answer is 9114



Example 2
Calculate 96 * 112
Solution
Use the same method. Let's select 100 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 96-100 = -4 and 112-100 is 12. So write it as
96    :   -4
112  :   12
Take the diagonal sum to get the left side of the product. That is 96+12 = 108 (Or 112-4 = 108).
For the right side, find the product of the differences. That is -4*12 = -48. Since it is -ve, we need to make it as +ve. For this borrow 1 from our left hand side 108. This borrowed 1 becomes 100 and our right hand side becomes 100+(-48) = 52. This is our right hand side
Since we borrowed one from left hand side, left hand side is 107
So answer is 10752



Example 3
Calculate 103 * 115
Solution
Use the same method. Let's select 100 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 103-100 = 3 and 115-100 is 15. So write it as
103  :   3
115  :   15
Take the diagonal sum to get the left side of the product. That is 103+15 = 118 (Or 115+3= 118).
For the right side , find the product of the differences. That is 3*15 = 45.
So answer is 11845



Example 4
Calculate 122 * 89
Solution
Use the same method. Let's select 100 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 122-100 = 22 and 89-100 is -11. So write it as
122  :  22
89    :   -11
Take the diagonal sum to get the left side of the product. That is 122+(-11) = 111 (Or 89+22= 111).
For the right side , find the product of the differences. That is 22*(-11) = -242. Since it is -ve, we need to make it as +ve. For this borrow 3 from our left hand side 111. This borrowed 3 becomes 300 and our right hand side becomes 300+(-242) = 58. This is our right hand side
Since we borrowed 3 from left hand side, left hand side is 108
So answer is 10858



Example 5
Calculate 1024 * 989
Use the same method. Let's select 1000 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 1024-1000 = 24 and 989-1000 is -11. So write it as
1024  :  24
989    :  -11
Take the diagonal sum to get the left side of the product. That is 1024+(-11) = 1013 (Or 989+24= 1013).
For the right side, find the product of the differences. That is 24*(-11) = -264. Since it is -ve, we need to make it as +ve. For this borrow 1 from our left hand side 1013. This borrowed 1 becomes 1000 and our right hand side becomes 1000+(-264) = 736.
Since we borrowed 1 from left hand side, left hand side is 1012 now.
So our answer is 1012736



Example 6
Calculate 997 * 986
Use the same method. Let's select 1000 as the base (Closed to both of the numbers).Write these numbers with the difference from the base. That is 997-1000 = -3 and 986-1000 is -14. So write it as
997  : -3
986  :  -14
Take the diagonal sum to get the left side of the product. That is 997+(-14) = 983 (Or 986-3= 983).
For the right side, find the product of the differences. That is (-3)*(-14) = 42. But here 42 has only 2 digits whereas our base 1000 has three zeros. So write 42 as 042.
So our answer is 98304


अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...