猿问

生成所有案例 NUMBER LETTER NUMBER - php

您好,我想按此顺序列出该数组中所有可能情况的列表


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]);

        }

    }

}

但它不起作用,有什么帮助吗?


波斯汪
浏览 93回答 2
2回答

精慕HU

您的数组引用是错误的。对于一个简单的数组,当使用 foreach 时,$key几乎无关紧要,因为该出现的值将在$firstor中$second......foreach($a as&nbsp; $first){&nbsp; &nbsp; foreach($b as $second){&nbsp; &nbsp; &nbsp; &nbsp; foreach($c as $third){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $first . $second . $third . PHP_EOL;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}如果您在浏览器上输出此内容,请更改PHP_EOL为'<br>'

米琪卡哇伊

你差不多解决了。你不需要在这里使用密钥。这是代码<?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){&nbsp; &nbsp; foreach($b as $second){&nbsp; &nbsp; &nbsp; &nbsp; foreach($c as $third){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo ($first.$second.$third).PHP_EOL;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答