PHP Small note function pass value analysis PHP function return value PHP array php date Letter

Source: Internet
Author: User
1.php the way the function passes the parameter, whether to pass the address of the variable or the value of the passed variable;

1.1 Defining a class

Class penson{

Public $age;

Public $name;

}

Instantiate an Object

$zs =new Penson ();

$zs->age=10;

1.2 Defines a string, a number, an array, respectively;

$str = "string";

$num = "0";

$myArray = (10,100,100);

1.3 Defining a function

Funtion Test ($STR, $num, $arr, $obj) {

$str = "Change string";

$num = 100;

$arr [0]=0;

$obj->age= "100";

}

Test ($STR, $num, $arr, $zs);

After the function is executed, print separately:

Echo $str; String

Echo $num; 0

echo $arr [0]; 10

Echo $zs; 100

Conclusion: Characters, numbers, and arrays are passed into the function in the form of parameters, and the object is to pass the address of the object to the function inside, so when the function is finished, the current function is recycled in the memory stack, so the created variable is destroyed, so it doesn't affect the outside variables. But the object passed in is the address, in the function of the change is actually passed in the address to manipulate the object, the object can not directly access, only through the way of the address, so the function inside the modified object after the function is finished, its effect is still.

Of course, if you want other types of data like objects, the pass-through function is the address, in the function to modify the outside of the variable, this PHP can also do, as long as the transfer of the parameters of this can be done:

Test (& $str,& $num,& $arr, $zs);

Add a & symbol before the variable so that whatever the data type, the changes in the function will affect the variables outside the function.

2.MYSQLI_INSERT_ID ($con)

Sometimes when we insert into, we need to know the current insert data in the database automatically generated ID, this time you can use the mysqli_insert_id () method, the method with a parameter, the parameter is to perform the Inser database connection, If you do not add the return content, a warning will appear, but the insertion is successful.

3. In PHP view to get a non-existent variable is likely to error, such as: $_post["select"], if the select does not exist, will be an error, should try to use the Isset () method to determine whether the variable exists, and then the operation

4. When creating a table with MySQL, remember to set the encoding:

CREATETABLEmessage(

id int(10) auto_increment PRIMARYKEY NOTNULL,

username VARCHAR(16) NOTNULL,

message VARCHAR(32) NOTNULL,

timedatetime NOT NULL)

The following sentence is used to set the encoding, if not set may result in Chinese garbled in the database

ENGINE= MYISAM CHARACTERSETutf8 ;


The above introduces the PHP small note function Analysis of the value, including PHP, function aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.