第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PHP-獲取在多個(gè)索引中具有值的鍵

PHP-獲取在多個(gè)索引中具有值的鍵

PHP
絕地?zé)o雙 2023-10-15 15:51:17
您可以像這樣使用自定義查詢<?php$authorID = get_the_author_meta('ID');$args = array(    'post_type' => 'product',    'post_status' => 'publish'    'posts_per_page' => 12,    'product_cat' => 'pants'    'author'    => $authorID);$loop = new WP_Query( $args );?>        <div class="author_products">    <?php if ( $loop->have_posts() ) { ?>        <ul class="author_pubproducts">        <?php while ( $loop->have_posts() ) : $loop->the_post();            woocommerce_get_template_part( 'content', 'product' );        endwhile; ?>        </ul>        <?php        } else {            echo __( 'No products found', 'textdomain' );        }        wp_reset_postdata();    ?>希望能成功
查看完整描述

2 回答

?
狐的傳說(shuō)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊

這就是我要做的:


// I take first element of array as a source for indexes

foreach ($myArray[0] as $index => $item) {

    // next I extract all elements from all subarrays under current `$index`

    $values = array_column($myArray, $index);

    // then I filter values to remove nulls. 

    // This also removes 0, empty arrays, false, 

    // so maybe you should change filter process

    $values_filtered = array_filter($values);

    // if number of filtered items is same as in original array - no nulls found

    if (count($values_filtered) === count($values)) {

        echo $index;

        // optionally

        // break; 

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-10-15
?
一只名叫tom的貓

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊

盡管有一個(gè)公認(rèn)的答案,但我想我會(huì)分享一種使用 Laravel 集合來(lái)做到這一點(diǎn)的方法。


 $uniqueKeysWithValues = collect($myArray)->map(function($item){

    return array_keys( collect($item)->filter()->toArray() ); //filter will remove all null

 })->flatten()->unique();

這種方法將為您提供所有包含值的鍵,即使兩個(gè)鍵中都有值。


查看完整回答
反對(duì) 回復(fù) 2023-10-15
  • 2 回答
  • 0 關(guān)注
  • 134 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)