Php 数组推送,需要参数

Php 数组推送,需要参数,php,arrays,array-push,Php,Arrays,Array Push,嗨,我正在尝试推循环和阵列,并将其推到我的新阵列。我当前收到此错误 array\u push()要求参数1为数组、字符串 我无法理解为什么这不起作用,我的代码看起来是这样的 $data['text'] = array(); foreach( $this->xml['paragraphs']['paragraph'] as $array ) { array_push($array['text'], $data); } 我的阵列 [parag

嗨,我正在尝试推循环和阵列,并将其推到我的新阵列。我当前收到此错误

array\u push()要求参数1为数组、字符串

我无法理解为什么这不起作用,我的代码看起来是这样的

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

 [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,
                    )
在我看来,你颠倒了这两个参数。假设您正在迭代
$this->xml['parations']['parations']
并尝试将每个
$array['test']
结果推送到
$data
,它应该如下所示:

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

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

反之亦然。

您是否混淆了
$data
$array
?为什么要避免这样简单的解决方案:
$data[]=$array['text']?不,我没有把它弄混,我正在把它推到数组中你正在试图把
数组('text'=>array())
推到字符串
“实木…”
!伙计,为什么这听起来像是双关语?O_o@BrentFrench:别担心,我们都从某个地方开始
array_push($data, $array['text']);

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