Why not give the correct exit code?
My full code:
<?php
$numA_m = "2";
$res = '["110","2","1"]';
$numA_s = json_decode($res);
if ($numA_m == 1) {
$A_num_s = array("1", "2", "3", "4","110");
$A_nam_s = array("egh", "guide", "irl", "tic", "all");
}
if ($numA_m == 2) {
$A_num_s = array("1", "2","110");
$A_nam_s = array("sub", "forg","all");
}
$Rsp = str_replace($A_num_s, $A_nam_s, $numA_s);
$Rsp_In = str_replace($A_nam_s, $A_num_s, $Rsp);
echo '<pre>';
print_r($Rsp);
echo '<p>';
echo '<pre>';
print_r($Rsp_In);
?>
The output should be:
Array (
[0] => all
[1] => forg
[2] => sub
)Array (
[0] => 110
[1] => 2
[2] => 1
)
But it is like this:
Array
(
[0] => subsub0
[1] => forg
[2] => sub
)
Array
(
[0] => 110
[1] => 2
[2] => 1
)
What do i do?
This outputs the desired result
Explanation:
str_replace searches for the strings in the order you send them. So, if in your case you are searching for
1and then110, it will replace all occurrences of1before reaching the110.If you replace the
110first, it will be replaced as expected.