Php 比较两个数组,如果为true,则返回值-wordpress

Php 比较两个数组,如果为true,则返回值-wordpress,php,arrays,wordpress,Php,Arrays,Wordpress,我是一名初学者,尝试使用wordpress实现以下目标: 用户填写表单后,我将“位置”存储在数组中,然后存储在wp\u table\u wordpress中 然后我创建了另一个包含“location”的wp_表,然后将wp_表的内容检索到一个数组中 因此,如果第一个数组中的“位置”与第二个数组中的“位置”匹配 然后返回true 但幸运的是我被卡住了 /** * User fill form then data are insert into

我是一名初学者,尝试使用wordpress实现以下目标:

用户填写表单后,我将“位置”存储在数组中,然后存储在wp\u table\u wordpress中

然后我创建了另一个包含“location”的wp_表,然后将wp_表的内容检索到一个数组中

因此,如果第一个数组中的“位置”与第二个数组中的“位置”匹配 然后返回true

但幸运的是我被卡住了

                /**
            * User fill form then data are insert into an wp table then an array 

             */
            global $wpdb;

            $name =  $_POST['name'];
            $location = $_POST['location'];
            $service = $_POST['service'];
            $email = $_POST['email'];

            $wpdb->insert('wp_searchform',
                 array(
                      'name'=>$name,
                      'location'=>$location,
                      'service'=>$service,
                      'email'=>$email
                 ),
                 array( 
                      '%s',
                      '%s',
                      '%s',
                      '%s'
                 )
            );

            /**
            * Retrieve data from a wp_table with a mysql join based on location then stored results in an arrays

             */

            $results = $wpdb->get_results( "
                SELECT pro_name
                FROM wp_searchform
                JOIN wp_pro ON wp_searchform.location = wp_pro.location
                LIMIT 0 , 30
               ");

               if ($arraysAreEqual = ($wpdb[0] == $results[0])) 
               {
               echo $results[0]->pro_name;
               }
           else{
               echo "true";
           }
使用PHP,您可以在这两个数组上运行,并查看函数是否返回相似性


两个数组都需要具有相同的结构才能工作。

$location不是数组,那么为什么要检查$location[0]?很好,charlotte,我修改了代码,但仍然无法工作
var\u dump($results)这样做可以获得查询结果。您首先没有选择位置。您只得到字段pro_name。var_dump工作,但我得到的输出=>array(1){[0]=>object(stdClass){241(1){[“pro_name”]=>string(6)“verity”}=>我只想得到结果,而不是结构。您也应该在mysql查询中选择location字段,否则无法比较位置。var_dump()仅用于调试目的。请提供更多说明和/或与WordPress相关的实际示例。