3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '{ "showElement": "1", "degrees": [{ "Name": "Bachelor in Psychology", "Number": "53", "degree": "Bachelor\'s Degree" }, { "Name": "Certificate", "Number": "56", "degree": "Certificate" }, { "Name": "High School Diploma", "Number": "28", "degree": "High School" }, { "Name": "Bachelor in Sociology", "Number": "109", "degree": "Bachelor\'s Degree" }] }'; $str_arr = json_decode($str); foreach($str_arr->degrees as $k=>$val){ if($val->degree == 'Bachelor\'s Degree'){ $new['Bachelor'][] = $val; }else{ $new[] = $val; } } foreach($new['Bachelor'] as $aa){ $nameStr[]= $aa->Name; $numStr[] = $aa->Number; } $nameStr = implode(', ', $nameStr); $numStr = implode(', ', $numStr); $degree = 'Bachelor\'s Degree'; $new[] = (object) array($nameStr, $numStr, $degree); unset($new['Bachelor']); echo $json = json_encode($new); echo "<pre>"; print_r(json_decode($json));
Output for git.master, git.master_jit, rfc.property-hooks
[{"Name":"Certificate","Number":"56","degree":"Certificate"},{"Name":"High School Diploma","Number":"28","degree":"High School"},{"0":"Bachelor in Psychology, Bachelor in Sociology","1":"53, 109","2":"Bachelor's Degree"}]<pre>Array ( [0] => stdClass Object ( [Name] => Certificate [Number] => 56 [degree] => Certificate ) [1] => stdClass Object ( [Name] => High School Diploma [Number] => 28 [degree] => High School ) [2] => stdClass Object ( [0] => Bachelor in Psychology, Bachelor in Sociology [1] => 53, 109 [2] => Bachelor's Degree ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
170.13 ms | 407 KiB | 5 Q