MatheusVieira MatheusVieira - 6 months ago 14
PHP Question

Simple PHP Array Replace Text

Simple Question

I need to change second part of array to first.

$LANG = array (
'Completed' => 'Complété',
'Estimate updated' => 'Devis actualisé',
);


to

$LANG = array (
'Completed' => 'Completed',
'Estimate updated' => 'Estimate updated',
);


I try array_splice but without sucess.
Could some one help, i need to rewrite 500 lines.

ty

Answer

As you want to array keys as values,

Using array functions:

$out = array_combine(array_keys($LANG), array_keys($LANG));
print_r($out);

Use foreach:

foreach($LANG as $key => $val){
    $LANG[$key] = $key;
}

print_r($LANG);

Result:

Array
(
    [Completed] => Completed
    [Estimate updated] => Estimate updated
)