3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $secret = 'MySecretFromSiruMobile'; $fields = [ 'variant' => 'variant1', 'merchantId' => '123123', 'purchaseCountry' => 'FI', 'basePrice' => '12.34', 'taxClass' => 3, 'serviceGroup' => 3, 'customerFirstname' => '', 'customerLastname' => null, 'customerNumber' => '050 123 4567', ]; $fields = array_filter($fields); // Drop empty fields echo 'UNSORTED'; $signature = hash_hmac("sha512", implode(';', $fields), $secret); ksort($fields); // Sort by field name foreach ($fields as $key => $val) { echo "$key = $val\n"; } echo 'SORTED'; $signature = hash_hmac("sha512", implode(';', $fields), $secret); echo $signature; ?>
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
UNSORTEDbasePrice = 12.34 customerNumber = 050 123 4567 merchantId = 123123 purchaseCountry = FI serviceGroup = 3 taxClass = 3 variant = variant1 SORTEDd47113a4c231e67970e57a3af3d149958ed70191e1f21226f6751e99361d08b2aa93cd9680222781bf0bd8c58dec3e463416e6f44159b3432dad7f8fefa10cb7
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/qnlfH on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/qnlfH on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qnlfH on line 3
Process exited with code 255.