The example in this article describes the usage of negative limit of explode in php. Share it with everyone for your reference. The specific analysis is as follows:
explode -- Use one string to split another string into an array.
The parameters are:
array explode ( string separator, string string [, int limit] )
The last limit does not need to be filled in. At this time, the string will be divided according to the separator separator; if the limit is filled with a positive number, it will be divided into (limit+1) numbers from left to right, and if it is a negative number, it will be divided from the right Remove the limit array elements (the parameter is negative starting from php5.1), leaving the remaining parts to form an array.
For example:
$str="1 2 3 4 5 6"; print_r(explode(" " ,$str,-2));
will see:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
It can be seen that the two elements 5 and 6 have been deleted.
I hope this article will be helpful to everyone’s PHP programming design.