3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $userdata = unserialize('a:31:{s:9:"firstName";s:5:"Blake";s:8:"lastName";s:6:"Patton";s:5:"title";s:3:"Dev";s:11:"companyName";s:7:"Example";s:15:"companyLocation";s:5:"Idaho";s:5:"email";s:17:"lorem@example.com";s:7:"website";s:0:"";s:9:"address_1";s:12:"123 Fake St.";s:9:"address_2";s:0:"";s:11:"addressCity";s:9:"Fakeville";s:12:"addressState";s:2:"WA";s:14:"addressZipcode";s:6:"123456";s:5:"phone";s:12:"123-456-1234";s:3:"fax";s:0:"";s:18:"companyDescription";s:0:"";s:25:"checkIndustryOrganization";s:2:"on";s:28:"checkTechnicalStaffingAgency";s:2:"on";s:10:"checkOther";s:2:"on";s:7:"addlBiz";s:1:"1";s:8:"addEntry";s:1:"1";s:14:"addDescription";s:13:"Ipsm Sit Imut";s:10:"addWebsite";s:0:"";s:34:"checkContractManufacturingServices";s:2:"on";s:24:"checkEngineeringServices";s:2:"on";s:33:"checkTechnicalSalesRepresentative";s:2:"on";s:20:"checkTestingServices";s:2:"on";s:11:"checkLabels";s:2:"on";s:31:"checkMarketingMaterialsProvider";s:2:"on";s:6:"table1";s:2:"35";s:6:"table2";s:2:"36";s:12:"paypal_token";s:20:"EC-9RS395813D9318137";}'); foreach($userdata as $key=>$val){ $split = preg_split('/(?=[A-Z])/',$key); if($split[0]=='check'){ if($val == 'on'){ $category = ''; foreach($split as $name){ if($name!='check'){ $category .= $name.' '; } } $categories[]=trim($category); } } unset($split, $name, $key, $val, $category); } var_dump($categories); var_dump($userdata);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(9) { [0]=> string(21) "Industry Organization" [1]=> string(25) "Technical Staffing Agency" [2]=> string(5) "Other" [3]=> string(31) "Contract Manufacturing Services" [4]=> string(20) "Engineering Services" [5]=> string(30) "Technical Sales Representative" [6]=> string(16) "Testing Services" [7]=> string(6) "Labels" [8]=> string(28) "Marketing Materials Provider" } array(31) { ["firstName"]=> string(5) "Blake" ["lastName"]=> string(6) "Patton" ["title"]=> string(3) "Dev" ["companyName"]=> string(7) "Example" ["companyLocation"]=> string(5) "Idaho" ["email"]=> string(17) "lorem@example.com" ["website"]=> string(0) "" ["address_1"]=> string(12) "123 Fake St." ["address_2"]=> string(0) "" ["addressCity"]=> string(9) "Fakeville" ["addressState"]=> string(2) "WA" ["addressZipcode"]=> string(6) "123456" ["phone"]=> string(12) "123-456-1234" ["fax"]=> string(0) "" ["companyDescription"]=> string(0) "" ["checkIndustryOrganization"]=> string(2) "on" ["checkTechnicalStaffingAgency"]=> string(2) "on" ["checkOther"]=> string(2) "on" ["addlBiz"]=> string(1) "1" ["addEntry"]=> string(1) "1" ["addDescription"]=> string(13) "Ipsm Sit Imut" ["addWebsite"]=> string(0) "" ["checkContractManufacturingServices"]=> string(2) "on" ["checkEngineeringServices"]=> string(2) "on" ["checkTechnicalSalesRepresentative"]=> string(2) "on" ["checkTestingServices"]=> string(2) "on" ["checkLabels"]=> string(2) "on" ["checkMarketingMaterialsProvider"]=> string(2) "on" ["table1"]=> string(2) "35" ["table2"]=> string(2) "36" ["paypal_token"]=> string(20) "EC-9RS395813D9318137" }