Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use negative limit of explode in php

Shulou Source: shulou.com Published: 2022-06-03 19:47:32 09月17日 Update

This article is about how to use negative limit of explode in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

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 final limit can not be filled, then all the string will be split according to the separator separator; if limit is positive, it will be divided into (limit+1) numbers from left to right; if it is negative, limit array elements will be removed from the right (the parameter is negative, starting from php5.1), leaving the rest to form an array.

Such as:

$str= "1 2 3 4 5 6"; print_r (explode ("", $str,-2))

You will see:

Array ([0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4)

It can be seen that 5 and 6 elements have been deleted.

Thank you for reading! This is the end of the article on "how to use the negative limit of explode in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Negative number number element content parameter character string array more article good practical can not two article positive number see knowledge part part group Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology OPPO Reno NVidia MariaDB