PHP 5.4 vs 5.3 app errors

I am building an web app with php and built it in php 5.4. However, I just realized my server run only 5.3 or 5.2. In my controller file I have this line of code

        $this->load->model('admin/upholstery_category_admin');
    $this->load->helper('url');

    if($method == 'add')
    {
        $categories = $this->db->get('category')->result();
line 158 here>>     $data = [];
        $data['cats'] = $categories;
        $data['message'] = '';

which is causes this error

 Parse error: syntax error, unexpected '[' in /home/content/51/6663351/html/application/controllers/admin.php on line 158

How do i change the syntax to correct this?


change:

$data = [];

to

$data =array();

As of PHP 5.4 you can also use the short array syntax, which replaces array() with []. So its only with 5.4 and later


[] is shortened syntax for arrays. So it should be:

$data = array();

PHP only added array literals in 5.4. Use this for PHP < 5.4:

$data = array();