为了账号安全,请及时绑定邮箱和手机立即绑定

生成所有案例 NUMBER LETTER NUMBER - php

生成所有案例 NUMBER LETTER NUMBER - php

PHP
波斯汪 2023-08-19 09:45:15
您好,我想按此顺序列出该数组中所有可能情况的列表NUMBER LETTER NUMBER$a = array("0","1","2","3","4","5","6","7","8","9");$b = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");$c = array("0","1","2","3","4","5","6","7","8","9");它将开始于0A0并以9Z9我尝试过这样的事情:foreach($a as $key1 => $first){    foreach($b as $key2 => $second){        foreach($c as $key3 => $third){            print_r($first[$key1].$second[$key2].$key3[$key3]);        }    }}但它不起作用,有什么帮助吗?
查看完整描述

2 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

您的数组引用是错误的。对于一个简单的数组,当使用 foreach 时,$key几乎无关紧要,因为该出现的值将在$firstor中$second......


foreach($a as  $first){

    foreach($b as $second){

        foreach($c as $third){

            echo $first . $second . $third . PHP_EOL;

        }

    }

}

如果您在浏览器上输出此内容,请更改PHP_EOL为'<br>'


查看完整回答
反对 回复 2023-08-19
?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

你差不多解决了。你不需要在这里使用密钥。这是代码


<?php


$a = array("0","1","2","3","4","5","6","7","8","9");

$b = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

$c = array("0","1","2","3","4","5","6","7","8","9");


foreach($a as $first){

    foreach($b as $second){

        foreach($c as $third){

            echo ($first.$second.$third).PHP_EOL;

        }

    }

}


查看完整回答
反对 回复 2023-08-19
  • 2 回答
  • 0 关注
  • 90 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信