标签云

微信群

扫码加入我们

WeChat QR Code


if you have non-associative arrays (or rather, array keys with numbers in them) in your data, adding a 'if (is_numeric($key)) $key = "item";' at the start of the foreach block (before is_array) does the trick.

2018年09月26日27分00秒

In order to be functional with numeric arrays too, add $fKey = is_numeric($key) ? 'numericValue' : $key; before if(is_array($value)) statement, and use $fKey in the rest of foreach statement.

2018年09月26日27分00秒

Oh VassilisGr, I made something like that there: if(is_numeric($key)) { $key = 'node'; } and moved the function write outside, you can't declare twice the same function, but Conrad will now that. (Shit, I saw now disq comment haha)

2018年09月26日27分00秒

Extending SimpleXML to do that is a pretty neat idea!

2018年09月25日27分00秒

i am modify your code and post that as answer

2018年09月25日27分00秒

Cool but doesn't work if you make assoc array like this: array('123' => 'asdf') Probably you should check every key for being a number.

2018年09月25日27分00秒