<?php $cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle']; var_export( array_reduce( $cities, function($result, $city) { $result[$city[0]][] = $city; return $result; } ) );
You have javascript disabled. You will not be able to edit any code.