Jump to content

Remove spaces from array keys


clay1

Recommended Posts

I've got an associative array from pg_fetch_array which ends up having spaces in some of the keys due to spaces in the column names(no I can't change them).

 

I want to use extract($array) but obviously the spaces create an issue accessing my variables.

 

How can I go from

 

	$lead = pg_fetch_array($result, $i, PGSQL_ASSOC);
extract($lead);

 

To something where I won't have any spaces?

Link to comment
https://forums.phpfreaks.com/topic/194104-remove-spaces-from-array-keys/
Share on other sites

Oh.

 

Maybe, try setting it as a variable

$street_address = $lead['street address']

or change the value in config/mysql/whatever

 

Well that is what the extract() is for. I was trying to avoid typing out each of the hundred variables. Like I said I can't change the column names.

 

Isn't there a way I can create a new array with the correct key names?

 

like foreach($lead) $lead['key'] = str_replace($lead['key']

 

Something along those lines

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.