php-tips

php扩展

Tips

array_column函数

array_column():第二个参数为null,指定第二维数组里的键为第三个参数,可以提取该键对应的值为一维的键值

$arr = [
['id'=>'a','name'=>'A'],
['id'=>'b','name'=>'B'],
['id'=>'c','name'=>'C']
];
$res = array_column($arr,null,'id');
/*
$res = [
'a'=>['id'=>'a','name'=>'A'],
'b'=>['id'=>'b','name'=>'B'],
'c'=>['id'=>'c','name'=>'C']
];
*/

php和java的哈希macSha256加密

Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec signingKey = new SecretKeySpec(appSecret.getBytes(), "HmacSHA256");
mac.init(signingKey);
byte[] signData = mac.doFinal(encodedStr.getBytes());
byte[] resultBytes = Base64.getEncoder().encode(signData);
signatureResult = new String(resultBytes, "UTF-8");
base64_encode(hash_hmac('sha256', $str, $this->appSecret, true))

查看php.ini的文件位置

php --ini

![WeChat111b3a8227c5190eda96fe19820a9d8c.png](https://alon-image-130
5333140.cos.ap-shanghai.myqcloud.com/blog/WeChat111b3a8227c5190eda96fe19820a9d8c.png)

composer

切换源

  • 腾讯云
composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer
  • 官方源
composer config -g repo.packagist composer https://repo.packagist.org
  • 查看当前源
composer config -g -l |grep "repositories.packagist.org.url"

xdebug

php.ini中xdebug的配置

[xdebug]
zend_extension="xdebug.so"
xdebug.mode = debug
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003
xdebug.start_with_request=yes
xdebug.idekey = xdebug
xdebug.discover_client_host=false
xdebug.log_level=0