将新的组合数组推送到PHP数组
我有以下代码。这将从SQL表(“db”)中获取字段,并准备在datatable(“dt”)中使用它们 它打印了这个将新的组合数组推送到PHP数组,php,sql,arrays,datatable,Php,Sql,Arrays,Datatable,我有以下代码。这将从SQL表(“db”)中获取字段,并准备在datatable(“dt”)中使用它们 它打印了这个 [{"authors":"John Smith; Paul Phillips","editors":"Robert Fox"},...] 现在,我想将第三个数组(people)推送到列中,该数组组合了前两个数组,但不替换它们,如 [{"authors":"John Smith; Paul Phillips","editors":"Robert Fox","people": "Jo
[{"authors":"John Smith; Paul Phillips","editors":"Robert Fox"},...]
现在,我想将第三个数组(people
)推送到列中,该数组组合了前两个数组,但不替换它们,如
[{"authors":"John Smith; Paul Phillips","editors":"Robert Fox","people": "John Smith: Paul Phillips; Robert Fox"},...]
如果只是试图添加到$columns的数组,
使用数组_merge()
结果应该是这样的:
array(4) {
[0]=>
array(2) {
["db"]=>
string(6) "Author"
["dt"]=>
string(7) "authors"
}
[1]=>
array(2) {
["db"]=>
string(6) "Editor"
["dt"]=>
string(6) "editor"
}
[2]=>
array(2) {
["db"]=>
string(6) "Person"
["dt"]=>
string(6) "person"
}
}
显示您希望最终数组的外观我希望它具有来自“Author”和“Editor”的db值。我说的是Show,不是description。请编辑您的问题以包含所需的结果/输出。好的,请检查我的编辑。问题顶部的PHP代码不会生成JSON(无论如何,它本身不会)。当我们看不到实际发生的事情时,很难帮助我们。请记住,我们完全不知道您目前正在做什么,或者正在尝试做什么。
$columns = array(
array( 'db' => 'Author', 'dt' => 'authors'),
array( 'db' => 'Editor', 'dt' => 'editor')
);
$person = array( 'db' => 'Person', 'dt' => 'person');
$newArray = array_merge($columns, $person);
array(4) {
[0]=>
array(2) {
["db"]=>
string(6) "Author"
["dt"]=>
string(7) "authors"
}
[1]=>
array(2) {
["db"]=>
string(6) "Editor"
["dt"]=>
string(6) "editor"
}
[2]=>
array(2) {
["db"]=>
string(6) "Person"
["dt"]=>
string(6) "person"
}
}