亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP array comparison unset problem
三叔
三叔 2017-06-29 10:08:35
0
8
1104

According to the value 5 4 1 contained in array two, unset the above array one without the key 5 4 1 to find the simplest way to write it. ha

// 數(shù)組一
array(6) {
  [1] => string(12) "伊凡木門"
  [2] => string(12) "夢天木門"
  [3] => string(15) "大自然地板"
  [4] => string(12) "尚品宅配"
  [5] => string(15) "德國都芳漆"
  [6] => string(12) "左右沙發(fā)"
}
數(shù)組二
array(3) {
  [0] => int(5)
  [1] => int(4)
  [2] => int(1)
}
三叔
三叔

reply all(8)
小葫蘆

I finally solved it with the following method. If the masters have a better way of writing, please feel free to enlighten me

    function get_vip_brand_list($uid = UID)
    {
        // 第一個數(shù)組
        $brand_list = config('sales_brand');
        // 第二個數(shù)組,反轉(zhuǎn)鍵和值
        $node       = array_flip(get_auth_node($uid,'sales.brand'));
        // 比較兩個數(shù)組的鍵名,并返回交集
        $vip_node   = array_intersect_key($brand_list, $node);
        return $vip_node;
    }
Ty80

You can use the functions of the array_diff series to operate. You can decide by yourself whether to use array_diff_key or assoc for the specific business.

世界只因有你

According to the value 5 4 1 contained in array 2, find the simplest way to write the unset of the above array 1 which does not exist and the key is not 5 4 1. Ha
means I don’t understand

<?php
$keys1 = array_keys($array1); // 獲取數(shù)組1key列表
$diffKeys = array_diff($keys1,$array2);// 結(jié)算數(shù)組1和數(shù)組2 key差集
foreach($diffKeys as $key){
    unset($array1[$key]);
}
typecho

Create a new array to store the values ??you want to retain. Then loop through array two, and then use the array_push function to push the values ??to be retained in array one into the newly created array.

大家講道理
$arr1 = array(
    1 => "伊凡木門", 
    2 => "夢天木門",
    3 => "大自然地板",
    4 => "尚品宅配",
    5 => "德國都芳漆",
    6 => "左右沙發(fā)"
);
$arr2 = array(5, 4, 1);
$keys = array_keys($arr1);
$remove = array_diff($keys, $arr2);
foreach ($remove as $key) {
    unset($arr1[$key]);
}
var_dump($arr1);
某草草

First flip array 2, and then find the intersection. I think your solution is the correct one

扔個三星炸死你
foreach($arr2 as $value) {
    foreach($arr1 as $key => $val) {
        if($value == $key) {
            unset($arr1[$key]);
        }
    }
}
print_r($arr1);
學(xué)習(xí)ing

You can learn about the array_slice function

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template