要清空键值或去掉字符串空格,可以使用以下方法:
清空键值:
array_values()函数将键值重新索引,例如:$array = array("a" => 1, "b" => 2, "c" => 3);
$array = array_values($array);
print_r($array);
输出:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
unset()函数将属性删除,例如:$object = (object) array("a" => 1, "b" => 2, "c" => 3);
unset($object->a);
unset($object->b);
unset($object->c);
print_r($object);
输出:
stdClass Object
(
)
去掉字符串空格:
trim()函数去掉字符串两端的空格,例如:$string = " hello world ";
$string = trim($string);
echo $string;
输出:
hello world
str_replace()函数将字符串中的空格替换为空,例如:$string = " hello world ";
$string = str_replace(" ", "", $string);
echo $string;
输出:
helloworld
下一篇:php 数组insert
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站