Question: I want to get the data from WordPress DB, pushed them into array and past the data to JS.

Got it all working except pushing the data into array in `foreach ($posts as $post)`.

Full method: 

```
        $array = array(); 
        $category_name = "locations";
        $args = array(
            'numberposts' => -1,
            'category_name' => $category_name
        );

        $posts = get_posts($args);      
        foreach ($posts as $post){
            array_push( $array, array(

                "title" => the_title($post->ID),
                "cnt" => the_content($post->ID),
                "id" => the_ID($post->ID),
                "link" => the_permalink($post->ID)

            )); 
        }

```

When I do `print_r($array)` i get a following mix:

```
Post 39http://localhost:8080/testing/post-3/Post 27http://localhost:8080/testing/post-2/Post 15http://localhost:8080/testing/post-1/Array
(
    [0] => Array
        (
            [title] => 
            [cnt] => 
            [id] => 
            [link] => 
        )

    [1] => Array
        (
            [title] => 
            [cnt] => 
            [id] => 
            [link] => 
        )

    [2] => Array
        (
            [title] => 
            [cnt] => 
            [id] => 
            [link] => 
        )

)

```

**What is going on? Why is the data not placed correctly into the array?**
Any suggestions much appreciated.

Answer: 
If in doubt, using a List is likely to be a better choice even if you know the length.

Using an array can be better for performance, but you need to be an expert to know when this is a good idea, and when it just makes your solution more complicated.

BTW: There is no such thing as `dynamic arrays` in Java.
If your only worry is not knowing how many elements you will need something like a list. By dynamic array, I'm assuming you want to manage your own array and resize it yourself? I wouldn't waste the effort unless you want to learn how it works. 

The good thing about Java is that List is an interface with different implementations (like ArrayList, LinkedList, Stack, Vector) depending on your needs. 

It looks like [ArrayList](http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html) might work for you.