There is an array:

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 ) ); 

For one array traversal, you need to make a sample (output 1 array), in which the value of the element [relateds] = 0446560280, as well as the element [price] has the smallest value.

Closed due to the fact that the issue is too common for the participants Sergiks , Bald , Denis , Mr. Black , Cerbo Jul 25 '16 at 15:19 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • MasterAlex, and you read the essence of the question? I have a question about how to output an array with a given element value, and not just the smallest value - cert
  • one
    and what is the problem, take all the arrays that have [relateds] = 0446560280; you do not need sorting, and then sort them by [price], as done by reference, then output the first value. Your question clearly states that there are problems with sorting, and not a problem with the derivation of all elements whose value is equal to something - MasterAlex
  • @cert, sorting and filtering are two different tasks (do not interfere with them in one pile). The sorting question is a duplicate. The question of a complex sample is probably not. Something tells me that you want to solve the problem in a single round of the array, but this is not visible from the question. If this is true - make the necessary changes to the question - Dmitriy Simushev
  • Dmitriy Simushev, thanks for the clarification, I’ll make some changes now. - cert
  • one
    if you want to share a solution to the problem you are facing, then issue the question / answer correctly : edit the original question and transfer the solution to the answer - Bald

1 answer 1

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; } 

You can use it like this:

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