0

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,
                    )
6
  • 3
    Are you mixing up $data and $array? Commented Jun 28, 2013 at 12:57
  • 1
    why do you avoid simple solutions like this: $data[] = $array['text'];? Commented Jun 28, 2013 at 12:58
  • No im not mixing it up im pushing it to the array Commented Jun 28, 2013 at 12:58
  • 1
    You are trying to push array('text' => array()) into the string "Solid wood..."! Commented Jun 28, 2013 at 13:00
  • Man, why does ^ this ^ sound like a double entendre? O_o Commented Jun 28, 2013 at 13:01

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

1 Comment

@BrentFrench: No worries, we all start somewhere. ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.