下面是我试图唯一/合并的数组和代码
$data['default_new'] = array_unique(array_merge($data['default'], $data['related']))
Array
(
[0] => Array
(
[keywords_id] => 8
[keyword] => Curling
[parent_id] => 5
[count] => 0
)
)
Array
(
[0] => Array
(
[keywords_id] => 8
[keyword] => Curling
[parent_id] => 5
[count] => 0
)
[1] => Array
(
[keywords_id] => 10
[keyword] => Catchers
[parent_id] => 6
[count] => 0
)
[2] => Array
(
[keywords_id] => 16
[keyword] => CES 2013
[parent_id] => 3
[count] => 0
)
)
它给了我一个字符串错误的数组:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/content_model.php
Line Number: 29
我以前遇到过 unique 和 merge 的问题,但从未修复过!
我正在使用代码点火器
以下是有关我正在使用 array_unique/merge 的函数的更多信息:
public function results($data, $searched)
{
$page['searched'] = $searched;
$page['is_active'] = $this->logic_model->is_active();
$data2 = array();
$data2['default_new'] = array_unique(array_merge($data['default'],
$data['related']));
}
第 29 行是$data2['default_new'] = array_u
$data
参数包含,default
并且regular
可以在上面看到。
数据转储:
array(3) {
["active"]=>
array(2) {
["id"]=>
string(1) "5"
["keyword"]=>
string(6) "Sports"
}
["related"]=>
array(1) {
[0]=>
array(4) {
["keywords_id"]=>
string(1) "8"
["keyword"]=>
string(7) "Curling"
["parent_id"]=>
string(1) "5"
["count"]=>
string(1) "0"
}
}
["default"]=>
array(3) {
[0]=>
array(4) {
["keywords_id"]=>
string(1) "8"
["keyword"]=>
string(7) "Curling"
["parent_id"]=>
string(1) "5"
["count"]=>
string(1) "0"
}
[1]=>
array(4) {
["keywords_id"]=>
string(2) "10"
["keyword"]=>
string(8) "Catchers"
["parent_id"]=>
string(1) "6"
["count"]=>
string(1) "0"
}
[2]=>
array(4) {
["keywords_id"]=>
string(2) "16"
["keyword"]=>
string(8) "CES 2013"
["parent_id"]=>
string(1) "3"
["count"]=>
string(1) "0"
}
}
}