I have main array:
$data_cities = Array (
[0] => Array (
[_type] => _items_city_sorting [item_city_sorting] => Moscow
)
[1] => Array (
[_type] => _items_city_sorting [item_city_sorting] => Saint-Petersburg
)
[2] => Array (
[_type] => _items_city_sorting [item_city_sorting] => Sochi
) )
I want to make another array just like:
$cities = array (
[1] => 'Moscow',
[2] => 'Saint-Petersburg',
[3] => 'Sochi' )
The function that I use returns only the last value
if ( $data_cities ) {
foreach ( $data_cities as $key => $city ) {
$cities[ $city->$key+1 ] = $city['item_city_sorting'];
}
}
Array ( [1] => Sochi )
What am I doing wrong? Thanks for the help=)
The main array was obtained using Carbon Fields if this is important