Choice from the area at the dowry value of keys



  • There's a mass:

    Array (
    [0] => Array (
        [product_id] => 27861642
        [percent] => 100
        [price] => 1437.132
        [relateds] => 044650C020
    )
    [1] => Array (
        [product_id] => 27818936
        [percent] => 100
        [price] => 1521.984
        [relateds] => 0446560280
    )
    );
    

    One round of the mass should be a sample (extract 1 mass) in which the element [relateds] = 0446560280 and the same element [price] is of the least importance.



  • Decision:

    function is_min_price_analogs(array $a, $b){
        $min_price = 9999999;
        $min_item = -1;
            if(count($a)){
                foreach($a as $i => $item){
                    if(isset($item['price'])  AND ($item['price'] < $min_price) AND ($item['articles'] !== $b)){
                        $min_price = $item['price'];
                        $min_item_key = $i; // ключ массива
                        $min_item = $item; // array
                    }
                }
            }
        return $min_item;
    }
    

    It is possible to use:

    $your_variable = is_min_price($products[2], $pattern);
    $название_переменной = is_min_price(входящий массив, значение_которое_ищем_в_элементе);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2