慕标琳琳
这是一种相当手动的方法,它从数据中提取价格并在过滤器中使用它...$items = array( array( 'id' => 104, 'book_id' => 32, 'price' => 55 ), array( 'id' => 117, 'book_id' => 76, 'price' => 65 ), array( 'id' => 135, 'book_id' => 77, 'price' => 65 ), array( 'id' => 100, 'book_id' => 78, 'price' => 65 ), array( 'id' => 101, 'book_id' => 21, 'price' => 85 ), array( 'id' => 107, 'book_id' => 35, 'price' => 90 ), array( 'id' => 108, 'book_id' => 64, 'price' => 90 ), array( 'id' => 130, 'book_id' => 101, 'price' => 100 ),);// extract unique prices out of the data$prices = array_unique( array_column( $items, 'price' ) );// sort the prices (ascending)sort( $prices );// extract three prices$threePrices = array_slice( $prices, 0, 3 );// filter the items that have a price in the lowest three prices array$lowestItems = array_filter( $items, function( $item ) use ( $threePrices ) { return in_array( $item['price'], $threePrices );});print_r( $lowestItems );// Array// (// [0] => Array// (// [id] => 104// [book_id] => 32// [price] => 55// )// // [1] => Array// (// [id] => 117// [book_id] => 76// [price] => 65// )// // [2] => Array// (// [id] => 135// [book_id] => 77// [price] => 65// )// // [3] => Array// (// [id] => 100// [book_id] => 78// [price] => 65// )// // [4] => Array// (// [id] => 101// [book_id] => 21// [price] => 85// )// // )