ServerSideSkittles ServerSideSkittles - 1 year ago 109
PHP Question

Strip whitespace from associative array Keys

I have an associative that outputs whitespace in the key and value. I need to strip the whitespace from first letter and also the last letter and keep the space inbetween.

I have tried

$stripResults = array_filter(array_map('trim', $results));

This strips the value perfectly but not the key. How do I strip the key and value?

mnv mnv
Answer Source

Keys must be processed separately:

$a = array_map('trim', array_keys($stripResults));
$b = array_map('trim', $stripResults);
$stripResults = array_combine($a, $b);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download