note 69525 added to control-structures.for
| From: | (notcom) | Date: | Fri, 08 Sep 2006 19:33:46 +0000 |
| Subject: | note 69525 added to control-structures.for | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116940@lists.php.net to get a copy of this message | ||
On the combination problem again...
It seems to me like it would make more sense to go through systematically. That would take nested
for loops, where each number was put through all of it's potentials sequentially.
The following would give you all of the potential combinations of a four-digit decimal combination,
printed in a comma delimited format:
for($a=0;$a<10;$a++){
for($b=0;$b<10;$b++){
for($c=0;$c<10;$c++){
for($d=0;$d<10;$d++){
echo $a.$b.$c.$d.", ";
}
}
}
}
Of course, if you know that the numbers you had used were in a smaller subset, you could just plunk
your possible numbers into arrays $a, $b, $c, and $d and then do nested foreach loops as above.
- Elizabeth
----
Server IP: 216.194.113.175
Probable Submitter: 65.91.97.66
----
Manual Page -- http://www.php.net/manual/en/control-structures.for.php
Edit -- https://master.php.net/note/edit/69525
Del: integrated -- https://master.php.net/note/delete/69525/integrated
Del: useless -- https://master.php.net/note/delete/69525/useless
Del: bad code -- https://master.php.net/note/delete/69525/bad+code
Del: spam -- https://master.php.net/note/delete/69525/spam
Del: non-english -- https://master.php.net/note/delete/69525/non-english
Del: in docs -- https://master.php.net/note/delete/69525/in+docs
Del: other reasons-- https://master.php.net/note/delete/69525
Reject -- https://master.php.net/note/reject/69525
Search -- https://master.php.net/manage/user-notes.php