How to convert all keys in a multi-dimenional array to snake_case?

前端 未结 7 2355
無奈伤痛
無奈伤痛 2021-02-14 09:08

I am trying to convert the keys of a multi-dimensional array from CamelCase to snake_case, with the added complication that some keys have an exclamation mark that I\'d like rem

相关标签:
7条回答
  • 2021-02-14 09:46

    I'd say you would have to write a function to copy the array (one level) and have that function call itself if any of the values is an array (a recursive function).

    • The exclamation marks are easily removed using trim()
    • The underscore before the uppercase characters in the middle can be added using a regex
    • After adding the underscore, the whole key can be converted to lower case

    What exactly do you need any specific help with?

    0 讨论(0)
提交回复
热议问题