def to_nested_php_args(data, prefix_key=None):
is_root = prefix_key is None<EOL>prefix_key = prefix_key if prefix_key else '<STR_LIT>'<EOL>if islist(data):<EOL><INDENT>data_iter = data if is_root else enumerate(data)<EOL>new_data = [] if is_root else {}<EOL><DEDENT>elif isdict(data):<EOL><INDENT>data_iter = list(data.items())<EOL>new_data = {}<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>'.format(type(data)))<EOL><DEDENT>if islist(new_data):<EOL><INDENT>def data_set(k, v):<EOL><INDENT>new_data.append((k, v))<EOL><DEDENT>def data_update(d):<EOL><INDENT>for k, v in list(d.items()):<EOL><INDENT>new_data.append((k, v))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>def data_set(k, v):<EOL><INDENT>new_data[k] = v<EOL><DEDENT>data_update = new_data.update<EOL><DEDENT>for key, value in data_iter:<EOL><INDENT>end_key = prefix_key + (str(key) if is_root else '<STR_LIT>'.format(key))<EOL>if _is_leaf(value):<EOL><INDENT>data_set(end_key, value)<EOL><DEDENT>else:<EOL><INDENT>nested_args = to_nested_php_args(value, end_key)<EOL>data_update(nested_args)<EOL><DEDENT><DEDENT>return new_data<EOL>
This function will take either a dict or list and will recursively loop
through the values converting it into a format similar to a PHP array which
Ubersmith requires for the info portion of the API's order.create method.