0

It shows

Parse error: syntax error, unexpected '[' in line 1

$test=  array (( [0] => array ( ['href'] => 'admin/manageusers', ['title'] => 'Setting', ['icon'] => 'icon-user', ['sub_menu'] => array ( [0] => array ( ['href'] => 'admin/manageusers/hoteladmins/edit-hoteladmin/29', ['title'] => 'Profile' ), [1] => array ( ['href'] => 'admin/manageusers/employee', ['title'] =>'Users' ), [2] => array ( ['href'] => 'admin/manageusers/pointssetting', ['title'] => 'Points' ), [3] => array ( ['href'] => 'admin/manageusers/transaction', ['title'] => 'Transaction' ) ) ) ) );

3 Answers 3

1

In declaring you should not use [0] as a key, just 0, so:

$test = array(
    0 => array(
        ['href']     => 'admin/manageusers',
        ['title']    => 'Setting',
        ['icon']     => 'icon-user',
        ['sub_menu'] => array(
            0 => array(
                ['href']  => 'admin/manageusers/hoteladmins/edit-hoteladmin/29',
                ['title'] => 'Profile'
            ),
            1 => array(
                ['href']  => 'admin/manageusers/employee',
                ['title'] => 'Users'
            ),
            2 => array(
                ['href']  => 'admin/manageusers/pointssetting',
                ['title'] => 'Points'
            ),
            3 => array(
                ['href']  => 'admin/manageusers/transaction',
                ['title'] => 'Transaction'
            )
        )
    )
);

Also if you want to set increasing keys, you can skip those keys:

$test = array(
    array(
        ['href']     => 'admin/manageusers',
        ['title']    => 'Setting',
        ['icon']     => 'icon-user',
        ['sub_menu'] => array(
            array(
                ['href']  => 'admin/manageusers/hoteladmins/edit-hoteladmin/29',
                ['title'] => 'Profile'
            ),
            array(
                ['href']  => 'admin/manageusers/employee',
                ['title'] => 'Users'
            ),
            array(
                ['href']  => 'admin/manageusers/pointssetting',
                ['title'] => 'Points'
            ),
            array(
                ['href']  => 'admin/manageusers/transaction',
                ['title'] => 'Transaction'
            )
        )
    )
);
Sign up to request clarification or add additional context in comments.

6 Comments

This will produce numerous "Illegal offset type" warnings.
@faintsignal Really ? Why ?
Well what did you tell the OP to do fix with his initial array key? Same principle applies to subarrays.
@faintsignal Look at my answer again and check if it's incorrect because I do not see any mistakes.
The [] need to removed from all keys. Run the code.
|
1

Dont use SQUARE ([ ] ) brackets to define the new element and it will be OK.

Just look at the correct version:

$test = array(
    0 => array(
        'href' => 'admin/manageusers',
        'title' => 'Setting',
        'icon' => 'icon-user',
        'sub_menu' => array(
            0 => array(
                'href' => 'admin/manageusers/hoteladmins/edit-hoteladmin/29',
                'title' => 'Profile'
            ),
            1 => array('href' => 'admin/manageusers/employee', 'title' => 'Users'),
            2 => array('href' => 'admin/manageusers/pointssetting', 'title' => 'Points'),
            3 => array('href' => 'admin/manageusers/transaction', 'title' => 'Transaction')
        )
    )
);

3 Comments

[ ] are not "curly brackets".
Doh! what the hell is going on with me today, wow. Thank you @faintsignal !
No worries, it's just that we don't want to confuse the novices.
0
$test = array(
array(
    'href' => 'admin/manageusers',
    'title' => 'Setting',
    'icon' => 'icon-user',
    'sub_menu' => array(
        array(
            'href' => 'admin/manageusers/hoteladmins/edit-hoteladmin/29',
            'title' => 'Profile'
        ),
        array('href' => 'admin/manageusers/employee', 'title' => 'Users'),
        array('href' => 'admin/manageusers/pointssetting', 'title' => 'Points'),
        array('href' => 'admin/manageusers/transaction', 'title' => 'Transaction')
    )
  )
);

Remove all "[" and "]" as above

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.