3v4l.org

run code in 300+ PHP versions simultaneously
<?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; ?>

preferences:
72.19 ms | 402 KiB | 5 Q