嗨,我正试图通过和数组来推送循环,并将其推送到我的新数组中。我当前收到此错误。。
array_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,
)
int array_push ( array &$array , mixed $var [, mixed $... ] )
array
The input array.
var
The pushed value.
在我看来,你颠倒了这两个参数。假设您在$this->xml['paragraphs']['paragraph']
上迭代,并试图将每个$array['test']
结果推送到$data
,它应该是这样的:
array_push($data, $array['text']);
// equivalent:
// $data[] = $array['text'];
而不是相反。