Brent
Brent

Reputation: 2485

Array Push, expects parameter

Hi I am trying to push loop though and array and push it to my new array. I am currently getting this error..

array_push() expects parameter 1 to be array, string

I cannot work out why this is not working, my code looks like this.

    $data['text'] = array();
    foreach( $this->xml['paragraphs']['paragraph'] as $array )
    {
        array_push($array['text'], $data);
    }

My array

 [paragraphs] => Array
    (
        [paragraph] => Array
            (
                [0] => Array
                    (
                        [text] => Solid wood door leading to entrance hallway, doors leading to Lounge/ Dining room and Shower room, double radiator, solid wood frame sash window to front, painted wood panell ceiling with single light, Indian slate floor.
                    )

                [1] => Array
                    (
                        [text] => Solid wood frame sash window to front, double radiator, bathroom suite comrising: shower cubicle with obscure perspex panells, WC and vanity sink. Painted wood panel ceiling with single light. Heated towel rail,
                    )

Upvotes: 0

Views: 88

Answers (1)

Brad Christie
Brad Christie

Reputation: 101614

int array_push ( array &$array , mixed $var [, mixed $... ] )

array
    The input array.
var
    The pushed value.

it looks, to me, that you've reversed the two parameters. Assuming you're iterating over $this->xml['paragraphs']['paragraph'] and trying to push each $array['test'] result in to $data, it should look like this:

array_push($data, $array['text']);

// equivalent:
// $data[] = $array['text'];

Not the other way around.

Upvotes: 2

Related Questions