PHP一些小技巧

<?php
//1.重复字符串
$a = str_repeat("input", 5);
echo "$a";
//2.随机抽一个或者多个key
$a = array('a'=>'dog','b'=>'fish','c'=>'pig');
$b = array_rand($a);
echo $b;
//3.返回二维数组的一列,重新组成一个一维数组
$a=array( ['a'=>1,'b'=>2], ['a'=>3,'b'=>4], ['a'=>5,'b'=>6]);
array_column($a, 'b');
var_dump($b);	
//4.去除头尾空格的方法
$test = " 你好,我们很爱PHP123 ";
$test = preg_replace('/^( |\s)*|( |\s)*$/', '', $test);
var_dump($test);

猜你喜欢

转载自blog.csdn.net/qq_31164125/article/details/82876579