3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $string = '&client_sku=item1&service[0][name]=Relay&service[0][service_type]=RS&service[0][tier][0][from]=1&service[0][tier][0][to]=10&service[0][tier][1][from]=11'; parse_str($string, $output); $rowObjectExample = ''; foreach($output as $name => $value) { if(isset($output[$name])) { if(is_array($value)) { $i = 0; $length = count($value); foreach($value as $key=>$val) { $i++; $rowObjectExample .= $name.'_row '.$name.'Row'; if($length > 1) { $rowObjectExample .= ($i <= $length ? $key : ''); } $rowObjectExample .= ' = new '.$name.'_row()'.";\n\t"; if(is_array($val)) { foreach($val as $k=>$v) { if(is_array($v)) { $n = 0; $len = count($v); foreach ($v as $row=>$column) { if(is_array($column)) { foreach($column as $r=>$c) { $rowObjectExample .= $k.'_row '.$k.'Row'; $n++; if($len > 1) { $rowObjectExample .= ($n <= $len ? $row : ''); } $rowObjectExample .= '.'.$r.' = '.$c."\n\t"; } } } } else { $rowObjectExample .= $name.'Row'; if($length > 1) { $rowObjectExample .= ($i <= $length ? $key : ''); } $rowObjectExample .= '.'.$k.' = '.$v."\n\t"; } } } } } } } var_dump($rowObjectExample);
based on nichs
Output for 4.3.0 - 7.2.0
string(183) "service_row serviceRow = new service_row(); serviceRow.name = Relay serviceRow.service_type = RS tier_row tierRow0.from = 1 tier_row tierRow0.to = 10 tier_row tierRow.from = 11 "