Home > Article > Backend Development > How to replace array value with asterisk in php
Array_splice() can be used to replace array values with asterisks. If you only want to replace one value, you can use "array_splice(array, starting position, 1, "*")"; if you want to replace multiple values, you can use "array_splice(array, position, replacement number, replacement array)", array contains multiple replacement values.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use array_splice () function to replace the array value with asterisks.
array_splice() is a powerful function that can delete, insert, and replace elements.
Use the array_splice() function to replace a specified number of elements starting from a specified position. If multiple values are replaced, the replacement value can be an array.
array_splice($array,$start,$length,$replacement)
Parameters:
If a replacement operation is performed, the length value and the number of replacements need to be consistent.
Example 1: Replace one value of an array with an asterisk
<?php $arr=array(1,2,3,4,5); var_dump($arr); array_splice($arr,1,1,"*"); var_dump($arr); ?>
Example 2: Replace multiple values of an array The value is an asterisk
If multiple values are replaced, the replacement value can be an array; and the number of replacements and the length of the replacement array must be consistent.
<?php $arr=array(1,2,3,4,5); var_dump($arr); array_splice($arr,1,3,array("*","*","*")); var_dump($arr); ?>
The above is the detailed content of How to replace array value with asterisk in php. For more information, please follow other related articles on the PHP Chinese website!