I am trying to remove all spaces in array keys names i.e. str_replace(\' \',\'\',$value) (or worst cast scenario replace them with underscores (_) )
and I am trying
You can pass an array to str_replace
so it's much cleaner and easier to just do this:
$my_array = array( 'one 1' => '1', 'two 2' => '2' );
$keys = str_replace( ' ', '', array_keys( $my_array ) );
$results = array_combine( $keys, array_values( $my_array ) );
Result:
array(2) {
["one1"]=>
string(1) "1"
["two2"]=>
string(1) "2"
}
Example: https://glot.io/snippets/ejej1chzg3