A
A
aks03vova2018-03-29 21:42:45
PHP
aks03vova, 2018-03-29 21:42:45

How does str_replace work?

Code like this:

$one = ['a','b'];
$two = ['b', 'a'];
$str = 'ab';
echo str_replace($one, $two, $str);

Outputs aa .
How to force output ba and how does it all work in general?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-03-29
@Stalker_RED

In your case, all the letters a are replaced by b
O3Into.png, it turns out 'bb',
then all b are changed to a
VqQf6m.png, it turns out 'aa'

// Выводит: яблорехкорех орех (по вышеуказанной причине)
$letters = array('я', 'о');
$fruit   = array('яблоко', 'орех');
$text    = 'я о';
$output  = str_replace($letters, $fruit, $text);
echo $output;
example from documentation
something like this: I understand that you want something else, but I don’t want to guess. Try to describe what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question