fork(4) download
  1. <?php
  2.  
  3. function flattenArray($arr) {
  4. $output = [];
  5.  
  6. foreach ($arr as $key => $value) {
  7. if (is_array($value)) {
  8. foreach(flattenArray($value) as $flattenKey => $flattenValue) {
  9. $output["${key}.${flattenKey}"] = $flattenValue;
  10. }
  11. } else {
  12. $output[$key] = $value;
  13. }
  14. }
  15.  
  16. return $output;
  17. }
  18.  
  19. $arr = [
  20. 'applicant' => [
  21. 'user' => [
  22. 'username' => true,
  23. 'password' => true,
  24. 'data' => [
  25. 'value' => true,
  26. 'anotherValue' => true
  27. ]
  28. ]
  29. ]
  30. ];
  31.  
  32. var_dump(flattenArray($arr));
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
array(4) {
  ["applicant.user.username"]=>
  bool(true)
  ["applicant.user.password"]=>
  bool(true)
  ["applicant.user.data.value"]=>
  bool(true)
  ["applicant.user.data.anotherValue"]=>
  bool(true)
}