Home > other >  need help for Split digits values php
need help for Split digits values php

Time:10-20

hello all i need help

i create code convert alphabet to his already defined powers

code working fine but i need output different

here is my code

input = "JHON";
       
    $remap = [
"a" => '1',
"A" => '1',
"b" => '2',
"B" => '2',
"c" => '3',
"C" => '3',
"J" => '100',
"H" => '10',
"O" => '90',
"N" => '200',
];
  $star =  str_replace(array_keys($remap), $remap, $input);

echo "$star"; 

here is output i received

1001090200

but i need output split with commas with split power like i need output like this

(100,10,90,200)

CodePudding user response:

Put the numbers into an array, then use implode() to create a string from that.

$array = [];
for ($i = 0; $i < strlen($input); $i  ) {
    $c = $input[$i];
    $array[] = $remap[$c];
}
$star = "(" . implode(',', $array) . ")";
echo $star;
  •  Tags:  
  • php
  • Related