3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = ' { "TrackResponse": { "Shipment": { "Package": { "TrackingNumber": "1Z7V015Y6870100000", "Activity": { "ActivityLocation": { "Address": { "City": "Caledon", "StateProvinceCode": "ON", "CountryCode": "CA" } }, "Status": { "Type": "I", "Description": "Departed from Facility", "Code": "DP" }, "Date": "20230322", "Time": "003100" }, "Activity2": [ { "ActivityLocation": { "Address": { "City": "Caledon", "StateProvinceCode": "ON", "CountryCode": "CA" } }, "Status": { "Type": "I", "Description": "Departed from Facility", "Code": "DP" }, "Date": "20230322", "Time": "003100" }, { "ActivityLocation": { "Address": { "City": "Caledon", "StateProvinceCode": "ON", "CountryCode": "CA" } }, "Status": { "Type": "I", "Description": "Arrived at Facility", "Code": "AR" }, "Date": "20230321", "Time": "115000" }, { "ActivityLocation": { "Address": { "City": "Windsor", "StateProvinceCode": "ON", "CountryCode": "CA" } }, "Status": { "Type": "I", "Description": "Departed from Facility", "Code": "DP" }, "Date": "20230320", "Time": "180900" } ] } } } } '; $data = json_decode($json); $activity = $data->TrackResponse->Shipment->Package->Activity; $activity2 = $data->TrackResponse->Shipment->Package->Activity2; if (is_object($activity)) { print_r(' Activity is an object '); } else { print_r(' Activity is NOT an object '); } if (is_array($activity)) { print_r(' Activity is an array '); } else { print_r(' Activity is NOT an array '); } if (is_object($activity2)) { print_r(' Activity2 is an object '); } else { print_r(' Activity2 is NOT an object '); } if (is_array($activity2)) { print_r(' Activity2 is an array '); } else { print_r(' Activity2 is NOT an array '); }
Output for 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Activity is an object Activity is NOT an array Activity2 is NOT an object Activity2 is an array

preferences:
82.4 ms | 1116 KiB | 4 Q