3v4l.org

run code in 300+ PHP versions simultaneously
<?php $countryCode = '+91'; $phoneNumber = '9028883545'; $callbackData = 'some text here'; $templateName = 'itk_auth_one_tap'; $languageCode = 'en'; $bodyValues = []; $otp = 'LIPSUM'; $headerValues = [$otp]; $buttonValues = [$otp]; // Using your exact code, notice that "buttonValues" doesn't match the expected output $data = [ "countryCode" => $countryCode, "phoneNumber" => $phoneNumber, "callbackData" => $callbackData, "type" => "Template", "template" => [ "name" => $templateName, "languageCode" => $languageCode, "bodyValues" => $bodyValues, "headerValues" => $headerValues, "buttonValues" => $buttonValues // This should be an OBJECT with a property named "0" ] ]; echo json_encode($data, JSON_PRETTY_PRINT); echo "\n\n"; // Let's try to fix it by forcing a stdClass $data = [ "countryCode" => $countryCode, "phoneNumber" => $phoneNumber, "callbackData" => $callbackData, "type" => "Template", "template" => [ "name" => $templateName, "languageCode" => $languageCode, "bodyValues" => $bodyValues, "headerValues" => $headerValues, "buttonValues" => (object) $buttonValues // Cast the array as stdClass ] ]; echo json_encode($data, JSON_PRETTY_PRINT);
Output for 8.1.30 - 8.1.33, 8.2.24 - 8.2.29, 8.3.5 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
{ "countryCode": "+91", "phoneNumber": "9028883545", "callbackData": "some text here", "type": "Template", "template": { "name": "itk_auth_one_tap", "languageCode": "en", "bodyValues": [], "headerValues": [ "LIPSUM" ], "buttonValues": [ "LIPSUM" ] } } { "countryCode": "+91", "phoneNumber": "9028883545", "callbackData": "some text here", "type": "Template", "template": { "name": "itk_auth_one_tap", "languageCode": "en", "bodyValues": [], "headerValues": [ "LIPSUM" ], "buttonValues": { "0": "LIPSUM" } } }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
89.7 ms | 408 KiB | 5 Q