- 论坛徽章:
- 0
|
- $array = array(
- '0'=>array('我','wo','I'),
- '1'=>array('是','shi','am'),
- '2'=>array('中国人','zhong guo ren','chinese')
- );
- echo echoarray($array , count($array)-1);
- function echoarray($carray , $allcount , $prekey = -1 , $prestring = '') {
- $prekey++;
- //if($prekey == $allcount) return ;
- foreach ($carray[$prekey] As $string) {
- $currstring = $prestring.$string;
- if($prekey == $allcount) {
- echo $currstring." \r\n";
- } else {
- echoarray($carray , $allcount , $prekey , $currstring);
- }
- }
- }
复制代码
典型的递归。
输出:
- 我是中国人
- 我是zhong guo ren
- 我是chinese
- 我shi中国人
- 我shizhong guo ren
- 我shichinese
- 我am中国人
- 我amzhong guo ren
- 我amchinese
- wo是中国人
- wo是zhong guo ren
- wo是chinese
- woshi中国人
- woshizhong guo ren
- woshichinese
- woam中国人
- woamzhong guo ren
- woamchinese
- I是中国人
- I是zhong guo ren
- I是chinese
- Ishi中国人
- Ishizhong guo ren
- Ishichinese
- Iam中国人
- Iamzhong guo ren
- Iamchinese
复制代码
如果要再要形成从"是中国人"这样的输出。 在外面再加一层foreach即可. |
|