douyun4524 2019-05-11 08:26
浏览 93

动态数组的嵌套循环

I have some results from a web form. I'm working with WP and I get a lot of term_id (from different taxonomy). In the frontend the form is "dynamic" for each kind of taxonomy (and i dont know before how many they are), I made a multiselect (all select have same NAME ex: terms[] ). When I process the term_IDs after form Submit I check each term_Id and put it in the right array. EX:

$option = isset($_POST['terms']) ? $_POST['terms'] : false;
if ($option) {
    $sql = "SELECT term_id,taxonomy FROM wp_term_taxonomy WHERE term_id IN (".implode(',',$option).") ";
    $term_tax = $wpdb->get_results($sql);//print_r($option); exit();        

    foreach ($term_tax as $tt)
    {
        $global[$tt->taxonomy][] = $tt->term_id;
    }

So in the end I have an array with 1 or N arrays. For each sub-array i have to do a nested cycle

EX: after process terms i have $gloabl[category] and $global[tag] I need to do

foreach($global[category] as $t)
{
     foreach($global[tag] as $x)
     {
        //do query with $t and $x
     }
}

I need to do a query with all combinations of term_ids for each subarray dynamically.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮