3v4l.org

run code in 300+ PHP versions simultaneously
<?php function extractColumnData($html,$key){ if(!preg_match("~\.put\('\d+',\s+(.+?)\);~",$html,$out)){ return "alert yourself of the preg_match failure"; } if(($array=@json_decode($out[1],true))===null && json_last_error()!==JSON_ERROR_NONE){ return "alert yourself of the json decode failure"; } return array_column(current(array_column(current($array),'options')),$key,'name'); // this assumes the static structure of your json/array data } $html=<<<HTML <script> HZ.productVariation.Manager.setSpaceId('33503761'); HZ.data.Variations.put('33503761', {"availVar": [{"id": "c", "label": "Color", "options": [{"name": "Chrome", "avail": 1, "stock": 1, "price": "$174.51", "quantity": "52", "imageId": "3eb1230d05775d3c"}, {"name": "SuperSteel", "avail": 1, "stock": 0, "price": "$341.40", "quantity": "0", "imageId": "d0a126f505775d3e"}]}], "curVar": {"c": "SuperSteel"}, "exactMatch": true}); HZ.productVariation.Manager.setSelector(HZ.productVariation.ListSelector); HZ.productVariation.Manager.setRenderer(HZ.productVariation.ViewSpaceRenderer); HZ.productVariation.Manager.setHistoryManager(new HZ.productVariation.BrowserHistoryManager("replace")); $('.variationSelectors').append(HZ.productVariation.Manager.drawSelectors('33503761')); HZ.productVariation.Manager.initUI(); </script> HTML; echo "avail => "; var_export(extractColumnData($html,'avail')); echo "\n----\n"; echo "stock => "; var_export(extractColumnData($html,'stock')); echo "\n----\n"; echo "price => "; var_export(extractColumnData($html,'price')); echo "\n----\n"; echo "quantity => "; var_export(extractColumnData($html,'quantity')); echo "\n----\n"; echo "imageId => "; var_export(extractColumnData($html,'imageId'));
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
avail => array ( 'Chrome' => 1, 'SuperSteel' => 1, ) ---- stock => array ( 'Chrome' => 1, 'SuperSteel' => 0, ) ---- price => array ( 'Chrome' => '$174.51', 'SuperSteel' => '$341.40', ) ---- quantity => array ( 'Chrome' => '52', 'SuperSteel' => '0', ) ---- imageId => array ( 'Chrome' => '3eb1230d05775d3c', 'SuperSteel' => 'd0a126f505775d3e', )

preferences:
121.43 ms | 408 KiB | 5 Q