XAMPP for OS X 8.2.4 安装 sodium扩展

1、安装libsodium库
libsodium是sodium扩展的依赖库,您需要先安装它。在Mac上,您可以使用Homebrew来安装libsodium:

brew install libsodium

2、安装sodium扩展

首先下载PHP源码,https://www.php.net/distributions/php-8.2.4.tar.gz(可选择对应版本);然后解压,进入ext下sodium目录;

使用phpize命令准备编译环境(确保您的phpize与XAMPP中的PHP版本相匹配)。
运行./configure脚本配置扩展。
使用make和sudo make install命令编译并安装扩展。
在php.ini文件中添加extension=sodium.so(在Windows上可能是extension=php_sodium.dll)来启用扩展。

完整命令如下:

/Applications/XAMPP/bin/phpize

./configure --with-php-config=/Applications/XAMPP/bin/php-config

make

sudo make install

PS:确保Mac已安装autoconf(如无,需先安装:brew install autoconf)


排列组合

//$words = array(‘china’,’mother’,’father’,’hello’,’welcome’);

//排列组合

$words = array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’);
$res = array();
getCombines($words, 5);
print_r($res);
function getCombines($arr, $len=0, $str=””) {
global $res;
$arr_len = count($arr);
if($len == 0){
$res[] = $str;
}else{
for($i=0; $i<$arr_len; $i++){
$tmp = array_shift($arr);
if (empty($str))
{
getCombines($arr, $len-1, $tmp);
}
else
{
getCombines($arr, $len-1, $str.”,”.$tmp);
}
array_push($arr, $tmp);
}
}
}