Help me to write a code

somebody please write a code in php for me

I have a six digit value 958469, i want to create other values similar to this value by changing every digit from 0-9 of every position which will result 54 unique similar value of this. I know how to do it in excel but want a code in php to print the result.

Result should be like this:

Value : 958469

result

058469
158469
258469
358469
458469
558469
658469
758469
858469
958469
908469
918469
928469
938469
948469
958469
968469
978469
988469
998469
950469
951469
952469
953469
954469
955469
956469
957469
959469
958069
958169
958269
958369
958469
958569
958669
958769
958869
958969
958409
958419
958429
958439
958449
958459
958469
958479
958489
958499
958460
958461
958462
958463
958464
958465
958466
958467
958468
958469

This will get you started:


// Break 958469 into digits
$p1 = 9; $p2 = 5; $p3 = 8; $p4 = 4; $p5 = 6; $p6 = 9;

for($p = 0; $p < 10; $p++) echo sprintf("%d%d%d%d%d%d\
",$p, $p2,$p3,$p4,$p5,$p6);
for($p = 0; $p < 10; $p++) echo sprintf("%d%d%d%d%d%d\
",$p1,$p, $p3,$p4,$p5,$p6);
for($p = 0; $p < 10; $p++) echo sprintf("%d%d%d%d%d%d\
",$p1,$p2,$p, $p4,$p5,$p6);
for($p = 0; $p < 10; $p++) echo sprintf("%d%d%d%d%d%d\
",$p1,$p2,$p3,$p, $p5,$p6);
for($p = 0; $p < 10; $p++) echo sprintf("%d%d%d%d%d%d\
",$p1,$p2,$p3,$p4,$p, $p6);
for($p = 0; $p < 10; $p++) echo sprintf("%d%d%d%d%d%d\
",$p1,$p2,$p3,$p4,$p5,$p );

You can generalize it and wrap it in a function.

Challenge accepted :slight_smile:


$x = 958469;
xx($x);
function xx($x = 958469)
{
  $x = (string) $x;
  $y = str_split($x);

  echo '<br />';
  foreach($y as $id => $val)
  {
    echo '<br />'; // .$id, ', ' .$val;
    for($i3=0; $i3<10; $i3++)
    {
      if($id > 0) // Miss the first item
      {
          echo substr($x, 0, $id);
      }    
      echo $i3 .substr($x, 1+$id);
     echo ($i3 < 9) ? ', &nbsp;  ' : NULL;
    }
  }
}

Output

058469, 158469, 258469, 358469, 458469, 558469, 658469, 758469, 858469, 958469
908469, 918469, 928469, 938469, 948469, 958469, 968469, 978469, 988469, 998469
950469, 951469, 952469, 953469, 954469, 955469, 956469, 957469, 958469, 959469
958069, 958169, 958269, 958369, 958469, 958569, 958669, 958769, 958869, 958969
958409, 958419, 958429, 958439, 958449, 958459, 958469, 958479, 958489, 958499
958460, 958461, 958462, 958463, 958464, 958465, 958466, 958467, 958468, 958469

Mr. John_Betong

Thanks for the reply, your code is very much near what i wanted. But your code prints 60 values in which 5 values are duplicate and one principal value for which we are generating similar number. In the result there should be 54 unique value excluding the main value.

I will be grateful if you can help me to create code to get this result.

If we are to “help” you and not “do it for you” you can help us by showing what you have tried and are having trouble with and don’t understand.
I love homework problems as much as the next guy, but my school days have long past.