我有两个数组,键是书本 ID(61、78、...等)
(1) book_width
(
[61] => 8.3
[72] => 8286.1
[78] => 6.4
[100] => 8407.0
[102] => 0.7
)
(2) book_height
(
[61] => 9.00
[72] => 150
[78] => 8.00
[100] => 150
[102] => 3.00
)
现在我想要一个数组,其中包含高度大于或等于宽度的书籍 ID
意味着我需要下面提到的数组
(2) book_dimension
(
/*book id*/ [78] => 8.00 //along their height or width(anyone)
[102] => 3.00
)
or only book id in a new array
(2) book_dimension
(
[0] => 78
[1] => 102
)
最佳答案
我相信这应该可以做到:
function compare_dimensions( $width, $height )
{
return $height < $width;
}
$result = array_uintersect_assoc( $array_width, $array_height, 'compare_dimensions' );
var_dump( $result );
编辑:
哎呀:比较应该是相反的。 (将 >= 更改为 <)
关于php - 比较php中两个数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2156868/