Add value to array with key
<p>I've got a code in my wordpress:</p>

<pre><code>        $wiadomosci = get_user_meta($user-&gt;ID,'wiadomosci', false);
        if($wiadomosci) {
            array_push($wiadomosci[$topic], $post-&gt;ID);
            update_user_meta($user-&gt;ID, 'wiadomosci', $wiadomosci);
        } else {
            $wiadomosci = array($topic =&gt; array($post-&gt;ID));
            add_user_meta($user-&gt;ID, 'wiadomosci', $wiadomosci);
        }
</code></pre>

<p>When a variable $wiadomosci doesnt exist I'm creating an array. $topic is the cateogory ID. So i'm getting this:</p>

<pre><code>Array
(
[0] =&gt; Array
    (
        [8] =&gt; Array
            (
                [0] =&gt; 139
            )

    )
</code></pre>

<p>)</p>

<p>8 is the category ID, and 139 post ID. Now when the variable $topic is 8 I want to add the post ID (for example 140) and get this:</p>

<pre><code>Array
(
[0] =&gt; Array
    (
        [8] =&gt; Array
            (
                [0] =&gt; 139
                [1] =&gt; 140
            )

    )

)
</code></pre>

<p>But I'm getting this:</p>

<pre><code>Array
(
[0] =&gt; Array
    (
        [0] =&gt; Array
            (
                [8] =&gt; Array
                    (
                        [0] =&gt; 139
                    )

            )

        [8] =&gt; 
    )

)
</code></pre>

<p>I'v tried replace</p>

<pre><code>array_push($wiadomosci[$topic], $post-&gt;ID);
</code></pre>

<p>with:</p>

<pre><code>$wiadomosci[$topic] = $post-&gt;ID
</code></pre>

<p>But it doesnt work. Any ideas?</p>