PHP-如何格式化数组中的URI列表以填充其他数组 [英] PHP - How to format list of URIs in an array to fill other array
问题描述
我有类似的问题,例如: PHP-如何格式为in_array 。
I have similiar problem like I had here: PHP - How to format data for in_array.
我在1个数据库字段中有一个 URI的逗号分隔列表
。所有URI都将用于排除数组中,例如Cookie,URI,ID。排除的Cookie是硬编码的,而不是URI。它们来自数据库查询,查询结果可以是多个,但不能超过10或20。那么如果数据库中有多个URI,如何格式化查询的输出?
I have a comma separated list of URIs in 1 database field
. All URIs will be used in an array of excludes like Cookies, URIs, IDs. Excluded Cookies are hardcoded, but not URIs. They come from a DB Query and the result of the query can be multiple, but not more 10 or 20. So how has the output from the query to be formated if there is more than 1 URI in database?
$lsc_exclude_uri_query = xtDBquery("SELECT
lsc.option_value // URIs
FROM lsc_config lsc
WHERE lsc.option_id = 9");
while ($exclude_uri_query = xtc_db_fetch_array($lsc_exclude_uri_query)) {
if (xtc_not_null($exclude_uri_query['option_value'])) {
$uris = $exclude_uri_query['option_value'];
}
}
// This is the array of excludes
if (!isset($_COOKIE[$lsc_customer_login]) && !isset($_COOKIE[$lsc_admin]) && !strstr($PHP_SELF, 'result from db query')) {
}
推荐答案
使用 explode()
将选项值分为数组。然后使用 array_merge()
将它们全部合并为一个结果数组。
Use explode()
to split the option value into an array. Then use array_merge()
to combine all of them into a single result array.
$urllist = [];
$lsc_exclude_uri_query = xtDBquery("SELECT
lsc.option_value
FROM lsc_config lsc
WHERE lsc.option_id = 9 AND lsc.option_value IS NOT NULL");
while ($exclude_uri_query = xtc_db_fetch_array($lsc_exclude_uri_query)) {
$uris = explode(','. $exclude_uri_query['option_value']);
$urllist = array_merge($urllist, $uris);
}
这篇关于PHP-如何格式化数组中的URI列表以填充其他数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!