Voting

: eight minus one?
(Example: nine)

The Note You're Voting On

douglasrich9215 at gmail dot com
7 years ago
I had an epiphany when try to handle NON-ASSOCIATIVE array forms in my controller. This little one liner can pretty much edit ANY kind of non-associative array. For example this one just returns an array of values inputed by a new user.

The $data value is the the json_decoded() value of a register form.
Here is used str_replace, you could definitely do a number of things like preg matches and other things.

$readyToProcessForUser = array_combine(str_replace("new_user_", "", array_keys($data)), $data);

You could also do the same for the values.

$readyToProcessForUser = array_combine(array_keys($data), str_replace("-", "", $data));

Or BOTH!
Use full if you don't want to walk an entire array and the keys through the same callback.

$readyToProcessForUser = array_combine(array_walk('trim', array_keys($data)), array_walk('custom_callback', array_values($data)));

<< Back to user notes page

To Top