fork download
  1. <?php
  2.  
  3. $list['item_lists'] = array(
  4. 'single',
  5. 'single',
  6. 'item1' => 'Item 1',
  7. 'single',
  8. 'single',
  9. 'item2' => 'Item 2',
  10. 'item3' => 'Item 3',
  11. 'item4' => 'Item 4',
  12. 'group' => array(
  13. 'subgroup' => 'value',
  14. ),
  15. );
  16.  
  17. function reconvert($array,$del,$path=array()){
  18. $string="";
  19. foreach($array as $key=>$val){
  20. if(!isset($key)){
  21. $key="";
  22. }
  23. if(is_string($val) || is_numeric($val)){
  24. $string.=implode("",$path).$key.$del.$val."\n";
  25. } else if(is_bool($val)){
  26. $string.=implode("",$path).$key.$del.($val?"True":"False")."\n";
  27. } else if(is_null($val)){
  28. $string.=implode("",$path).$key.$del."NULL\n";
  29. }else if(is_array($val)=='array') {
  30. $path[]=$key.$del;
  31. $string.=reconvert($val,$del,$path);
  32. array_pop($path);
  33. } else {
  34. throw new Exception($key." has type ".gettype($val).' which is not a printable value.');
  35. }
  36. }
  37. return $string;
  38. }
  39.  
  40. echo reconvert($list['item_lists'] ,"|");
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
0|single
1|single
item1|Item 1
2|single
3|single
item2|Item 2
item3|Item 3
item4|Item 4
group|subgroup|value