1

I have an array thats like this:

Array
(
    [core.login.site] => Array
        (
            [6] => 1
            [2] => 1
        )

    [core.admin] => Array
        (
            [20] => 1
            [1] => 1
            [8] => 1
            [53] => 1
        )

    [core.manage] => Array
        (
            [7] => 1
        )


)

Now I want to unset value in the array [core.admin]. I tried unsetting the value like this:

$rolid = 53;
unset($array['core.admin'][$rolid]);

But this doesn't seem to work

2 Answers2

1

I found the problem: it was a misplaced ; after my unset php -l didn't report.

user3071284
  • 6,955
  • 6
  • 43
  • 57
0

Replace your first block of code with this:

 $array = Array
    (
        'core.login.offline' => Array
            (
                6 => 1
            ),

        'core.admin' => Array
            (
                20 => 1,
                1 => 1,
                8 => 1,
                53 => 1
            )
    );

You have plenty of syntax error, I recommend you to have a refresher on php.

Array keys must be either string or integer, so you have to replace those brackets with single / double quotes. You must also add comma after an array value if there is another proceeding value / key-value pair.

  • 2
    OP is probably showing us the output from `print_r();` and just put `$array =` in front of it. – Rizier123 Jan 07 '16 at 23:30
  • Isn't unfair to downvote based on "probably", even if you're right when I answered right based on given informations? – regner.christopher Jan 07 '16 at 23:32
  • I'm pretty sure it's the output from `print_r()`, because it exactly looks like this. Also since OP wrote perfectly valid code under it, I'm sure he knows how to define an array correctly. And from the current information given it the question it's not possible to reproduce the error, so the question should be closed as such – Rizier123 Jan 07 '16 at 23:52
  • The output was an print_r, but i found the problem. i mis placed a ; after my unset php -l didn't report it. – Bas van den Dikkenberg Jan 08 '16 at 09:04
  • The isue was resolved – Bas van den Dikkenberg Jan 17 '16 at 16:16