3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $results = json_decode('{"queryNum":1,"profileName":"Bank of Hawaii 1","profileID":"3790328098","metricSetNum":1,"subQueryNum":1,"iterationNum":1,"status":"SUCCESS","sampled":false,"totalResults":17,"columnHeadersArr":{"dim1_1":"Headline 1","dim2_1":"Headline 2","dim3_1":"Description","met1_1":"Impressions","met2_1":"Clicks","met3_1":"Clicks","met3_2":"Impressions","met4_1":"Cost","met4_2":"Clicks","met5_1":"Cost","met6_1":"Conversions","met7_1":"Cost","met7_2":"Conversions","met8_1":"Conversions","met8_2":"Clicks","met_f1_1":"Clicks"},"rows":{"|BOH Checking Account|Bank on the Go|Open a new account online. It\u2019s quick & easy. Apply now!":{"dim1_1":"BOH Checking Account","dim2_1":"Bank on the Go","dim3_1":"Open a new account online. It\u2019s quick & easy. Apply now!","met1_1":13573,"met2_1":3151,"met3_1":23.21520666028144,"met4_1":0.5270168200571248,"met5_1":1660.63,"met6_1":"164","met7_1":10.12579268292683,"met8_1":5.204696921612187},"|BOH Checking Account|Bank on the Go|Convenience checking plus online & mobile banking. Apply now!":{"dim1_1":"BOH Checking Account","dim2_1":"Bank on the Go","dim3_1":"Convenience checking plus online & mobile banking. Apply now!","met1_1":3916,"met2_1":568,"met3_1":14.504596527068436,"met4_1":0.6359330985915492,"met5_1":361.21,"met6_1":"9","met7_1":40.13444444444444,"met8_1":1.584507042253521},"|Bank on the Go|BOH Checking Account|Convenience checking plus online & mobile banking.":{"dim1_1":"Bank on the Go","dim2_1":"BOH Checking Account","dim3_1":"Convenience checking plus online & mobile banking.","met1_1":"762","met2_1":"156","met3_1":20.47244094488189,"met4_1":0.5787820512820513,"met5_1":90.29,"met6_1":"11.00","met7_1":8.208181818181819,"met8_1":7.051282051282051},"|BOH Checking Account|Bank on the Go|Convenience checking plus online & mobile banking.":{"dim1_1":"BOH Checking Account","dim2_1":"Bank on the Go","dim3_1":"Convenience checking plus online & mobile banking.","met1_1":"13027","met2_1":"1376","met3_1":10.562677515928456,"met4_1":1.0944767441860466,"met5_1":1506,"met6_1":"57.00","met7_1":26.42105263157895,"met8_1":4.142441860465116},"|Bank on the Go|BOH Checking Account|Open a new account online. It\u2019s quick & easy. Apply now!":{"dim1_1":"Bank on the Go","dim2_1":"BOH Checking Account","dim3_1":"Open a new account online. It\u2019s quick & easy. Apply now!","met1_1":454,"met2_1":97,"met3_1":21.365638766519822,"met4_1":0.34628865979381446,"met5_1":33.59,"met6_1":"1.00","met7_1":33.59,"met8_1":1.0309278350515463},"|BOH Online Checking Account|Bank on the Go|Open a new account online. It\u2019s quick & easy. Apply now!":{"dim1_1":"BOH Online Checking Account","dim2_1":"Bank on the Go","dim3_1":"Open a new account online. It\u2019s quick & easy. Apply now!","met1_1":"266","met2_1":"45","met3_1":16.917293233082706,"met4_1":0.526,"met5_1":23.67,"met6_1":"0.00","met7_1":"","met8_1":0}}}',true); $sortArr = json_decode('{"inQuerySort":{"field":"ConversionRateManyPerClick_perc","direction":"desc","fieldType":"met"},"sortOrig":{"field":"ConversionRateManyPerClick_perc_desc;2nd:Clicks_desc","direction":""},"auto":false,"secondary":{"direction":"desc","field":"Clicks","fieldType":"met","inQuerySort":{"field":"Clicks","direction":"desc","fieldType":"met"},"col":"met2_1"},"intention":"custom","field":"ConversionRateManyPerClick_perc","direction":"desc","fieldType":"met","col":"met8_1"}',true); $sortValuesArr = []; foreach ($results["rows"] as $key => &$row) { $sortValuesArr["first"][$key] = $row[$sortArr["col"]]; $sortValuesArr["second"][$key] = ($sortArr["secondary"]["col"] ? $row[$sortArr["secondary"]["col"]] : ""); } array_multisort( $sortValuesArr["first"], ($sortArr["direction"] == "desc" ? SORT_DESC : SORT_ASC), ($sortArr["fieldType"] == "dim" ? SORT_NATURAL : SORT_NUMERIC), $sortValuesArr["second"], ($sortArr["secondary"]["direction"] == "desc" ? SORT_DESC : SORT_ASC), ($sortArr["secondary"]["fieldType"] == "dim" ? SORT_NATURAL : SORT_NUMERIC), $results["rows"] ); var_dump($sortValuesArr); $ar1 = array(10, 100, 100, 0); $ar2 = array(1, 3, 2, 4); array_multisort($ar1, $ar2); var_dump($ar1); var_dump($ar2);
based on mXOJg
Output for 5.6.38 - 7.3.0rc3
array(2) { ["first"]=> array(6) { ["|Bank on the Go|BOH Checking Account|Convenience checking plus online & mobile banking."]=> float(7.0512820512821) ["|BOH Checking Account|Bank on the Go|Open a new account online. It’s quick & easy. Apply now!"]=> float(5.2046969216122) ["|BOH Checking Account|Bank on the Go|Convenience checking plus online & mobile banking."]=> float(4.1424418604651) ["|BOH Checking Account|Bank on the Go|Convenience checking plus online & mobile banking. Apply now!"]=> float(1.5845070422535) ["|Bank on the Go|BOH Checking Account|Open a new account online. It’s quick & easy. Apply now!"]=> float(1.0309278350515) ["|BOH Online Checking Account|Bank on the Go|Open a new account online. It’s quick & easy. Apply now!"]=> int(0) } ["second"]=> array(6) { ["|Bank on the Go|BOH Checking Account|Convenience checking plus online & mobile banking."]=> string(3) "156" ["|BOH Checking Account|Bank on the Go|Open a new account online. It’s quick & easy. Apply now!"]=> int(3151) ["|BOH Checking Account|Bank on the Go|Convenience checking plus online & mobile banking."]=> string(4) "1376" ["|BOH Checking Account|Bank on the Go|Convenience checking plus online & mobile banking. Apply now!"]=> int(568) ["|Bank on the Go|BOH Checking Account|Open a new account online. It’s quick & easy. Apply now!"]=> int(97) ["|BOH Online Checking Account|Bank on the Go|Open a new account online. It’s quick & easy. Apply now!"]=> string(2) "45" } } array(4) { [0]=> int(0) [1]=> int(10) [2]=> int(100) [3]=> int(100) } array(4) { [0]=> int(4) [1]=> int(1) [2]=> int(2) [3]=> int(3) }