<?php $arr1 = []; $arr2 = [ ['淡', '深'], ]; $arr3 = [ ['淡', '深'], ['红', '黄', '蓝'] ]; function descartes($arr) { // 取出第一个 $result = array_shift($arr); // 直到没有数据 while ($arr2 = array_shift($arr)) { $arr1 = $result; // 重置 $result = []; foreach ($arr1 as $item1) { foreach ($arr2 as $item2) { $result[] = "${item1}${item2}"; } } } return $result; } echo json_encode(descartes($arr1), JSON_UNESCAPED_UNICODE) . PHP_EOL; // null echo json_encode(descartes($arr2), JSON_UNESCAPED_UNICODE) . PHP_EOL; // ["淡","深"] echo json_encode(descartes($arr3), JSON_UNESCAPED_UNICODE) . PHP_EOL; // ["淡红","淡黄","淡蓝","深红","深黄","深蓝"]