[英]A 'for each' PHP loop within an existing Array[]
I'm trying to loop an array from a database into an existing array.我正在尝试将数据库中的数组循环到现有数组中。 The two codes work well alone but I only get an error when trying to combine them.... for example...
这两个代码单独工作得很好,但我只在尝试组合它们时出现错误......例如......
The current array (which is a list of spammer databases) look as such...当前数组(它是垃圾邮件发送者数据库的列表)看起来是这样的......
$dnsbl_lookup=array(
"access.redhawk.org",
"all.s5h.net",
"blacklist.woody.ch",
);
While the array I am trying to add is as so...虽然我试图添加的数组是这样的......
$values = $myOptions['re_i_'];
foreach ($values as $value) {
echo '"'.$value['database'].'",';
}
And I end up with the following...我最终得到以下...
$dnsbl_lookup=array(
"access.redhawk.org",
"all.s5h.net",
"blacklist.woody.ch",
$values = $myOptions['re_i_'];
foreach ($values as $value) {
echo '"'.$value['database'].'",';
}
);
Which, of course, only returns an error.当然,这只会返回错误。 Does anyone know how to do this properly or if it is even possible?
有谁知道如何正确地做到这一点,或者甚至可能吗?
It looks like you want to merge the $dnsbl_lookup
values with the database
column values in $myOptions
, which you can do with array_merge
and array_column
:看起来您想将
$dnsbl_lookup
值与$myOptions
的database
列值合并,您可以使用array_merge
和array_column
:
$dnsbl_lookup = array(
"access.redhawk.org",
"all.s5h.net",
"blacklist.woody.ch"
);
$dnsbl_lookup = array_merge($dnsbl_lookup, array_column($myOptions['re_i_'], 'database'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.