I have noticed a strange behaviour of a str_replace function.
Can you tell me why instead of number 3 in no_2 i get no_4 ?
Here is the case:
$pattern = array(1,2,3);
$change = array(1,3,4);
$sql = "SELECT * FROM %s WHERE no_1 IN (%s) AND no_2 IN (%s) AND no_3 IN (%s)";
$test_multiply[] = str_replace($pattern, $change, $sql);
Which gives:
Array ( [0] => SELECT * FROM %s WHERE no_1 IN (%s) AND no_4 IN (%s) AND no_4 IN (%s) )
Can you tell me what should I do to receive no_3 instead of no_2?
The documentation for
str_replace()says (quoting) :I believe you are precisely in this situation :
no_2gets replaced tono_3— because of the second item in your$patternand$changearraysno_3gets replaced tono_4— because of the thid item in your$patternand$changearraysTo avoid that specific situation, you might try reversing the order of the items in those two arrays :
And you’d get the following result :