Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of insufficient length of php

Shulou Source: shulou.com Published: 2022-06-02 14:40:30 09月19日 Update

This article mainly introduces "how to solve the problem of insufficient php length". In daily operation, I believe many people have doubts about how to solve the problem of insufficient php length. Xiaobian consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "how to solve the problem of insufficient php length"! Next, please follow the small series to learn together!

Solution to insufficient php length: 1, create a PHP sample file;2, through the "str_pad($value,2,0,STR_PAD_LEFT);" way to achieve string fixed length is not enough to supplement other strings.

Operating environment: Windows 7 system, PHP7.1 version, DELL G3 computer

How to solve PHP length problem?

PHP string fixed length, not enough to complement other strings

// str_pad(string with padding, length after padding, padding string, padding position) $result=["7","6","8","4","3","23","27","9","5","19","10","21"]; if($result){ foreach ($result as $key => $value){ $result[$key]=str_pad($value,2,0,STR_PAD_LEFT); } //$result =["07","06","08","04","03","23","27","09","05","19","10","21"]

Related Introduction:

The str_pad() function fills the string with a new length.

syntax

str_pad(string,length,pad_string,pad_type)

parameters

string Required. Specifies the string to fill. Length is required. Specify the new string length. If the value is less than the original length of the string, nothing is done. pad_string Optional. Specifies the string to be used for padding. The default is blank. pad_type

Optional. Specifies which side of the padding string.

Possible values:

STR_PAD_BOTH -Fill both sides of the string. If not even, the right side gets extra padding. STR_PAD_LEFT -Left side of padded string. STR_PAD_RIGHT -The right side of the padded string. Default. At this point, the study on "how to solve the problem of insufficient php length" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Characters strings length problems learning not enough right more help original practical next locations even numbers functions methods parameters files articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB Microsoft MySQL macOS