Colleagues, programmers, good afternoon, I need your help.
The strtr string handler replaces keys with their value, and vice versa with the help of array_flip , but it doesn’t work out how I use the array_flip to swap the value back into their keys?
Code example:
<?php $code = array ( 'н' => '1', 'а' => '2', 'п' => '3', 'л' => '4', 'р' => '5' ); $text = 'нас предали явка провалена.'; $cipher = strtr($text, $code); echo "Оригинал: ($text)<br/> Шифровка: ($cipher)<br/>"; $rash = array_flip($cipher); echo "Расшифровка: ($rash)";
conclusion:
Original: (we were betrayed turnout failed.) Encryption: (12s 35ed24 and yav2 352424e12.)
Array_flip () expects parameter 1 to be array, string given on line number 18 Transcript: ()
strtr
returns a string ..... respectively, you have a string in$cipher
....... and they tell you about it that you substitute a string, not an array ........ respectively ... you need to have an inverse$code
array, and in the$rash
variable add the string in the same way as in$cipher
just give$cipher
as the input string, and instead of the characters being replaced - that reverse array - Alexey Shimansky$otv = strtr($text, $rash);
should not be$text
, but$cipher
..... If that inverse array (which is inverse to the$code
array) is not used anywhere, then you can immediately write$rash = strtr($cipher, array_flip($code));
- Alexey Shimansky