Elements are the wrong way to do this. Elements are used to visualize or display similar fragments several times in several views. You can pass variables from view to element, but not vice versa.
I would recommend placing the array in your AppController as follows:
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function beforeFilter(Event $event) {
$this->set('districts', array(
__('Region A') => array(
__('district 1') => __('district 1'),
__('district 2') => __('district 1'),
__('district 3') => __('district 1')
),
__('Region B') => array(
__('district 4') => __('district 4'),
__('district 5') => __('district 5'),
__('district 6') => __('district 6')
)
));
}
}
?>
, $districts, .
, AppController:
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function beforeFilter(Event $event) {
$this->districts = array(
__('Region A') => array(
__('district 1') => __('district 1'),
__('district 2') => __('district 1'),
__('district 3') => __('district 1')
),
__('Region B') => array(
__('district 4') => __('district 4'),
__('district 5') => __('district 5'),
__('district 6') => __('district 6')
)
);
}
}
?>
, :
<?php
namespace App\Controller;
class SomeController extends AppController
{
public function index() {
$this->set('districts', $this->districts);
}
}
?>