fork(1) download
  1. <?php
  2. $x = array(
  3. 'group' => array(
  4. 'key' => 'value',
  5. 'key_second' => 'value2'
  6. ),
  7. 'secondgroup'=> array(
  8. 'thirdgroup'=> array(
  9. 'key'=>'value3',
  10. 'bool'=>true,
  11. 'NULL'=>NULL
  12. )
  13. )
  14. );
  15.  
  16. function reconvert($array,$del,$path=array()){
  17. $string="";
  18. foreach($array as $key=>$val){
  19. if(is_string($val) || is_numeric($val)){
  20. $string.=implode($del,$path).$del.$key.$del.$val."\n";
  21. } else if(is_bool($val)){
  22. $string.=implode($del,$path).$del.$key.$del.($val?"True":"False")."\n";
  23. } else if(is_null($val)){
  24. $string.=implode($del,$path).$del.$key.$del."NULL\n";
  25. }else if(is_array($val)=='array') {
  26. $path[]=$key;
  27. $string.=reconvert($val,$del,$path);
  28. array_pop($path);
  29. } else {
  30. throw new Exception($key." has type ".gettype($val).' which is not a printable value.');
  31. }
  32. }
  33. return $string;
  34. }
  35. echo reconvert($x,"|");
  36.  
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
group|key|value
group|key_second|value2
secondgroup|thirdgroup|key|value3
secondgroup|thirdgroup|bool|True
secondgroup|thirdgroup|NULL|NULL