I want to create new array.
Value of element in array should be blank.
Key of array should another array's value.
$Oldarr = Array
(
[0] => Webseite,
[1] => Bestellung,
[2] => Verkäufer,
[3] => Käufer,
[4] => Warenwert,
[5] => Lieferkosten,
[6] => Produktname,
[7] => Article Nr,
[8] => Anzahl
);
And New array shoud be
$Newarr = Array
(
['Bestellung'] => '',
['Verkäufer'] => '',
['Käufer'] => '',
['Warenwert'] => '',
['Lieferkosten'] => '',
['Produktname'] => '',
['Article Nr'] => '',
['Anzahl'] => ''
);
use array_flip to make key as values and values as keys.
$newarr = array_flip($Oldarr);
If you need to set blank values as well then you can use array_fill_keys like:
$newarr = array_flip($Oldarr);
$newarr = array_fill_keys($newarr, null);//for null values
$newarr = array_fill_keys($newarr, '');//for empty string values
Edited:
only array_fill_keys will work in your scenario (credit goes to @Sougata Bose who commented here)
$newarr = array_fill_keys($Oldarr, '');//for empty string values
You can use following code:
$new = array_flip($Oldarr);
$new = array_fill_keys($Oldarr,'');