Recently used PHP Functions

Source: Internet
Author: User

Mysql_insert_id ()
This data item ID is obtained directly after data is inserted into the database.
Details

Http://cn2.php.net/manual/zh/function.mysql-insert-id.php

Substr
Truncate string

Str_replace
(PHP 4, PHP 5)
Str_replace-replace all occurrences of the search string with the replacement string
String replacement function

 

Delete array elements
For more information, see Article In string array, delete array elements (in OSO), unset is used, but there is a defect. For example, $ A is an array:
<? $ A = array ("red", "green", "blue", "yellow ");
Count ($ A); // get 4
Unset ($ A [1]); // deletes the second element.
Count ($ A); // get 3
Echo $ A [2]; // The array contains only three elements. In this example, we want to get the last element, but we get blue,
Echo $ A [1]; // No value
?>
That is to say, after the elements in the array are deleted, the number of elements in the array (obtained using count () has changed, but the array subscript has not been rearranged, you must also use the key before the array to delete the corresponding value.
Later, I used another method. In fact, it was not called a "method" at all. Instead, I used the PhP4 ready-made function array_splice ().
<? $ A = array ("red", "green", "blue", "yellow ");
Count ($ A); // get 4
Array_splice ($ A,); // deletes the second element.
Count ($ A); // get 3
Echo $ A [2]; // obtain yellow
Echo $ A [1]; // get blue
?>
Put this Program Compared with the previous one, we can see that array_splice () not only deletes the elements, but also rearranges the elements, in this way, there will be no null values (such as $ A [1] In values) between the elements of the array.
Array_splice () is actually a function to replace array elements. However, if no replacement value is added, the elements are simply deleted. The usage of array_splice () is as follows:
Array array_splice (array input, int offset [, int length [, array replacement])
The input parameter is an array to be operated. The offset parameter starts from the first element and starts from the first element when the offset parameter is negative; length is the number of elements to be replaced/deleted. If it is omitted, it starts from offset to the end of the array. It is also positive and negative. The principle is the same as offset. relacement is the value to be replaced.

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.