php - 比较php中两个数组的值

标签 php mysql comparison

我有两个数组,键是书本 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 );

编辑:
哎呀:比较应该是相反的。 (将 >= 更改为 <)

文档:http://docs.php.net/array_uintersect_assoc

关于php - 比较php中两个数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2156868/

相关文章:

mysql - 如何将csv文件导入mysql表并自动递增

javascript - 使用javascript中的if条件比较for循环中的两个字符串

php - 计算重复记录

php - 如何修复 sendmail.php 不起作用?

php - 将日期导入 MySQL

php - 使用多个 PHP 处理 PHP servlet 的 session

c# - ASP.NET - C# 与 VB.NET - 间接差异和您最初可能不会考虑的事情

mysql - 将 varchar 字段与数字零进行比较会返回如同真正匹配的结果

php - 尝试安装 FOSUserBundle 但出现错误

php - Apache 两个应用程序一个域共享语言/en - Magento 和 Wordpress