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

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

PHP比較兩個(gè)數(shù)組,但第一個(gè)數(shù)組的所有值都需要在第二個(gè)

PHP比較兩個(gè)數(shù)組,但第一個(gè)數(shù)組的所有值都需要在第二個(gè)

PHP
白板的微信 2022-12-11 10:38:00
再次 - 抱歉過(guò)去的愚蠢解釋......我沒(méi)有得到我的錯(cuò)誤,這讓我發(fā)瘋......所以我有兩個(gè)數(shù)組——一個(gè)是普通數(shù)組,另一個(gè)是多維數(shù)組。但這也許無(wú)關(guān)緊要,因?yàn)槲曳纸饬藘蓚€(gè)要與數(shù)組進(jìn)行比較的字符串...這是我的代碼:<?php$arr1 = ["folds" => '01,03,'];if($arr1['folds'][strlen($arr1['folds'])-1] == ","){    $arr1['folds'] = substr($arr1['folds'], 0, -1);}$check = explode(",", $arr1['folds']);$arr2 = [    ["Offer" => "Website", "folds" => '01'],    ["Offer" => "Development", "folds" => '01,03,05,10,14,15,21,22,'],    ["Offer" => "Testing", "folds" => '01,03,04,10,15,22'],    ["Offer" => "Sales", "folds" => '01,03,10,22,']];$arr3 = [];foreach($arr2 as $i_arr){    if($i_arr['folds'][strlen($i_arr['folds'])-1] == ","){        $i_arr['folds'] = substr($i_arr['folds'], 0, -1);    }    $tocheck = explode(",", $i_arr['folds']);    foreach($check as $chk){        if(in_array($chk, $tocheck)){            $arr3[] = $i_arr;        }    }}print_r($arr3);?>所以我至少有兩個(gè)數(shù)組($check 和 $tocheck)- $check 內(nèi)容搜索或過(guò)濾值就像你想命名的那樣。$tocheck 來(lái)自于數(shù)據(jù)庫(kù),得到要過(guò)濾的信息。我的代碼沒(méi)有按照我的意愿執(zhí)行 - 因?yàn)?in_array($check[x], $tocheck[y]) 檢查 $check 中的所有值和 $tocheck 中的所有值 - 但是當(dāng)只有一個(gè)值適合時(shí)它說(shuō)“真的”。我的挑戰(zhàn)是當(dāng) $check 中的所有值也在 $tocheck 中時(shí),只在 $arr3 中打印 $i_arr,而不是只打印一個(gè)...有人有想法嗎?
查看完整描述

2 回答

?
慕神8447489

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

循環(huán)并$arr2檢查strpos():$arr1["folds"]


<?php


$arr1 = ["folds" => '02,04'];


$arr2 = [

    ["Offer" => "Website", "folds" => '02'],

    ["Offer" => "Development", "folds" => '02,04,09']

];


$arr3 = [];

foreach($arr2 as $i_arr){

    if(isset($i_arr["folds"]) && strpos($i_arr["folds"], $arr1["folds"]) > -1){

        $arr3[] = $i_arr;

    }

}


print_r($arr3);


?>

輸出:


Array

(

    [0] => Array

        (

            [Offer] => Development

            [folds] => 02,04,09

        )


)

https://paiza.io/projects/_0nC44WHlZJpkdLOjm1Tkw


查看完整回答
反對(duì) 回復(fù) 2022-12-11
?
慕田峪9158850

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

這里的解決方案 - 也許它會(huì)幫助別人:


<?php

// Your code here!

$arr1 = ["folds" => '01,03,'];

if($arr1['folds'][strlen($arr1['folds'])-1] == ","){

    $arr1['folds'] = substr($arr1['folds'], 0, -1);

}

$check = explode(",", $arr1['folds']);


$arr2 = [

    ["Offer" => "Website", "folds" => '03'],

    ["Offer" => "Development", "folds" => '01,03,05,10,14,15,21,22,'],

    ["Offer" => "Testing", "folds" => '01,03,04,10,15,22'],

    ["Offer" => "Sales", "folds" => '01,03,10,22,']

];

$use = "no";


$arr3 = [];

foreach($arr2 as $i_arr){

    if($i_arr['folds'][strlen($i_arr['folds'])-1] == ","){

        $i_arr['folds'] = substr($i_arr['folds'], 0, -1);

    }

    $tocheck = explode(",", $i_arr['folds']);

    foreach($check as $chk){

        if(in_array($chk, $tocheck)){

            $use = "yes";

        } else {

            $use = "no";

            break;

        }

    }

    if($use == "yes"){

        $arr3[] = $i_arr;

    }

}


print_r($arr3);


?>


查看完整回答
反對(duì) 回復(fù) 2022-12-11
  • 2 回答
  • 0 關(guān)注
  • 141 瀏覽

添加回答

舉報(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)