about it as though I was a little tough ..I have been writing c programs and do not like to waste memory .. For the first time, the school asked us to do this project, and php was just less than a week away .. Because I don't know how database storage works. So I just want to ask if I put the shopping cart information in the database, and each information is giv
transmission problems
Compress complex data types into a string
Serialize () encodes variables and their values into text form
Unserialize () restore original variable
$ Stooges = array ('Moe', 'Larry ', 'Curly ');
$ New = serialize ($ stooges );
Print_r ($ new); echo"";
Print_r (unserialize ($ new ));
Result: a: 3: {I: 0; s: 3: "Moe"; I: 1; s: 5: "Larry"; I: 2; s: 5: "Curly ";}
Array ([0] => Moe [1] => Larry [2] => Curly)
When the serialized data is placed in a URL and transmitted between pa
Please read the previous article first
Refactoring
Even the most thoughtful and skilled programmers cannot foresee any nuance in a software project. The problem is always unexpected, the demand may be changing, and the result is that the code is optimized, shared, and replaced.
Refactoring is a common approach: check all your code to find the similarities and the similarities in which you can unify and simplify, making your code easier to maintain and extend. Refactoring also involves exploring
option variables to each item in your buyer's shopping cart in the above table. The first item in the shopping cart must be defined by the parameter ending with "_ 1", such as "item_name_1" and "amount_1. Similarly, the second item is named by the application variables "item_name_2" and "amount_2. Tip: The "_ x" value
-> products, $ callback); return round ($ total, 2) ;}$ my_cart = new Cart; // add the product and quantity to the shopping cart $ my_cart-> add ('butter ', 10); $ my_cart-> add ('milk', 3 ); $ my_cart-> add ('eggs', 12); // you can obtain the total price, with a sales tax of 3%. echo $ my_cart-> getTotal (0.03); // output 1196.4Note: the closure can USE the USE
"extends" to extend a class.
class test {
public function __construct() {
}
public function name() {
$this->xname('John');
}
private function showName($name) {
echo 'my name in test is '.$name;
}
}
class extendTest extends test {
public function __construct() {
parent::__construct();
}
private function showName($name) {
echo 'my name in extendTest is '.$name;
}
}
$test = new extendTest();
$test-
to the actual parameter when calling the function:
Function foo ($ bar ){
$ Bar. = 'and something extra .';
}
$ Str = 'This is a string ,';
Foo ($ str );
Echo $ str; // outputs 'This is a string ,'
Foo ( $ str );
Echo $ str; // outputs 'This is a string, and something extra .'
4. default value
The function can define the default values of the C ++ style, as follows:
Function makecoffee ($ type = "cappucino "){
Echo "Making a cup of $ type. \ n ";
}
Echo makecoffee ();
Echo makecoffee ("espresso
default value, as follows:
function Makecoffee ($type = "Cappucino") {
echo "Making a cup of $type. \ n";
}
Echo Makecoffee ();
echo Makecoffee ("espresso");
The output of this piece of code above is:
Making a cup of Cappucino.
Making a cup of espresso.
Note that when you use the default parameters, all parameters that have default values should be defined behind the parameters without default values, otherwise, they will not work as you would like.
5. Class (classes)
A class is a collect
Summary of PHP-based programming considerations. 1. php implicit ternary operators (? :) Priority problem: Example 1: Copy the code as follows: $ person $ whoor $ personlaruence; is actually equivalent to: $ personempty ($ who )? La
1. php implicit ternary operators (? :) Priority:
Example 1:
The code is as follows:
$ Person = $ who or $ person = "laruence ";//
result. this parameter is generally set to null.$ This-> pageUrl = "";// Extended field 1. the merchant can pass the required parameters. the original value is returned after the payment is completed and can be blank.$ This-> ext1 = $ MockOrder ['orderid'];// Extended from segment 2. the merchant can pass the required parameters. the original value is returned after the payment is completed, which can be blank.$ This-> ext2 = $ MockOrder ['ordertime'];// Bank code. if payType is 00, this value
parameter is required. // cannot be blank.
$ This-> signType = "4 ";
// The page address for receiving the payment result. this parameter is generally set to null.
$ This-> pageUrl = "";
// Extended field 1. the merchant can pass the required parameters. the original value is returned after the payment is completed and can be blank.
$ This-> ext1 = $ MockOrder ['orderid'];
// Extended from segment 2. the merchant can pass the required parameters. the original value is returned after the payment
Analyze the php creator mode and analyze the creation of php. Analysis of the php creator mode and the php creator mode: in the creator mode, the client is no longer responsible for object creation and assembly, but is responsible for object creation, analysis on php creatio
PHP disables page caching. PHP disables page caching. for example, if I have three pages. shopping cart 2. order address and payment method 3. when the order is generated 2-3, the order data is inserted to generate the order information and the PHP method to disable page cac
Simple analysis of PHP creator mode and analysis of PHP creation
Creator mode:
In the creator mode, the client is no longer responsible for the creation and assembly of objects, but rather the responsibility of creating the object to its specific creator class, the Assembly of responsibility to the Assembly class, the client pays the call to the object, thus clarifying the responsibilities of each class.Sc
session* Three steps to achieve the perfect, non-leakage**/function Sessiondestroy () {Session_destroy ();Setcookie (Session_name (), ", Time ()-3600);$_session = Array ();}?>
session resolves a problem where PHP allows you to store user information on the server for later use (i.e., user name, items in the shopping cart, etc.). However, the information for this
.\ ';
}
$str = \ ' This is a string, \ ';
Foo ($STR);
Echo $str; Outputs \ ' This is a string, \ '
Foo ( $str);
Echo $str; Outputs \ ' This is a string, and something extra.\ '
4. Default value
The function can define a C + + style default value, as follows:
function Makecoffee ($type = \ "Cappucino\") {
echo \ "Making a cup of $type. \\n\";
}
Echo Makecoffee ();
echo Makecoffee (\ "espresso\");
The output of this piece of code above is:
Making a cup of Cappucino.
Making a cup of espresso
This section describes how to call the php Tutorial class, apply for instructions, and use the previous instance methods and operation procedures of various types, let you know the construct destruct clone call wake sleep usage of the php class clearly.Simple shopping cartClass car
Introduction: This is a PHP tutorial. The detailed page of the application instance. It introduces the related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 326948 'rolling = 'no'>
PHP/MySQL
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.