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: 
You are doing it right.

List is an Interface and ArrayList is the implementation. If you do not care much for OO mambo-jumbo, here is how you can understand it.

List is the way you want to deal with the "system". You don't care much for anything else.

But the "system" has the freedom to implement it in several ways! ArrayList, LinkedList, Vector etc.

Once you understand this separation, then try to glean the differences and nuances between these implementations.
Lists (and their cousins, Map and Set) are a good choice for almost any use case. They eat a little more memory and add a small overhead compared to arrays, but offer a *much* richer API and generally code written agains an interface is much better reusable/flexible than code using a statically typed array.

One case where the java.util.Collections may add unacceptable overhead is when you want to store *primitive* data types (such as int, float etc), because to store such types you need to use wrappers (the collection classes only deal with objects). Wrapping can be mostly left to autoboxing, but one needs to be aware of the memory overhead. Apache commons (and possibly other libraries) also offer collection implementation that work with primitives directly.

You only want to work with arrays if you can't avoid it.