Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://stackoverflow.com/questions/64676862/how-to-encode-decode-string-to-decimal-number-in-php
- // As suggested in the comments, you can put it into hex and that into its numeric representation.
- $list = array(
- "string0",
- "string1",
- "string2",
- "string3",
- "string4",
- "string5",
- );
- function numberEncode($value){
- return hexdec(bin2hex($value));
- }
- function numberDecode($value){
- return hex2bin(dechex($value));
- }
- $list2 = array();
- foreach($list as $value){
- $list2[] = numberEncode($value);
- }
- print_r($list2);
- $list3 = array();
- foreach($list2 as $value){
- $list3[] = numberDecode($value);
- }
- print_r($list3);
- /*
- Array
- (
- [0] => 32497657065662256
- [1] => 32497657065662257
- [2] => 32497657065662258
- [3] => 32497657065662259
- [4] => 32497657065662260
- [5] => 32497657065662261
- )
- Array
- (
- [0] => string0
- [1] => string1
- [2] => string2
- [3] => string3
- [4] => string4
- [5] => string5
- )
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement