English 中文(简体)
如果数组相等数组 PHP
原标题:If array equal array PHP
  • 时间:2012-05-24 18:38:20
  •  标签:
  • php
  • arrays

能否让 成为 ? 因为我做不到, 你能帮我个忙吗?

Example: $array1([0] => Joe , [2] => Pairs ); $array2([0] => info => array([0] => joe ));

foreach($array2->info as $info){
    foreach($array1 as $name){
        if($name == $info[0]){
             echo  true ;
           }
           else{
             echo  false ;
           }
      }
  }

这是真实的代码,

数组 :

 Array
(
[0] => SimpleXMLElement Object
    (
        [companyLocationInfo] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [companyName] => AVIS
                        [name] => NYCC07
                        [line1] => 420 EAST 90TH STREET
                    )
                [2] => SimpleXMLElement Object
                    (
                        [companyName] => AVIS
                        [name] => NYCC06
                        [line1] => 310 EAST 64TH STREET
                    )
                [3] => SimpleXMLElement Object
                    (
                        [companyName] => AVIS
                        [name] => NYCC01
                        [line1] => 68 EAST 11TH STREET
                    )

            )

        [rates] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [pickupDropoffLocations] => Array
                            (
                                [0] => SimpleXMLElement Object
                                    (
                                        [companyName] => AVIS
                                        [name] => NYCC07
                                    )
                            )
                        [vehicleRentalPrefType] => CCAR
                        [rateAmount] => 83.99
                        [rateCurrency] => USD
                    )
                [2] => SimpleXMLElement Object
                    (
                        [pickupDropoffLocations] => Array
                            (
                                [0] => SimpleXMLElement Object
                                    (
                                        [companyName] => AVIS
                                        [name] => NYCC06
                                    )
                            )
                        [vehicleRentalPrefType] => CCAR
                        [rateAmount] => 110.54
                        [rateCurrency] => USD
                    )
                [3] => SimpleXMLElement Object
                    (
                        [pickupDropoffLocations] => Array
                            (
                                [0] => SimpleXMLElement Object
                                    (
                                        [companyName] => AVIS
                                        [name] => NYCC01
                                    )
                            )
                        [vehicleRentalPrefType] => CCAR
                        [rateAmount] => 210.65
                        [rateCurrency] => USD
                    )

            )

    )

)

这就是代码:

$results_array = array();

foreach($result[0]->rates as $rate) {
    foreach($result[0]->companyLocationInfo as $info) {
        if($info->name == $rate->pickupDropoffLocations[0]->name) {
            $results_array[] = array(
                 line1  => $info->line1,
                 name  => $info->locationDetails->name,
                 companyName  => $info->companyName,
                 vehicleRentalPrefType  => $rate->vehicleRentalPrefType
            );
        }
    }
}
print_r($results_array);

谢谢

最佳回答

您想要做的应该是可能的。 如果上面的代码是您正在实际尝试运行的代码, 那么您的第一个问题就是您要比较的值是 "Joe" “joe” , 而这些是不一样的 。

如果您想要对案件不敏感比较, 请使用 < code> if (strcasecmp( $var1, $var2) = = 0) (如果两个字符串相同, 不考虑案例, 则返回零 ) 。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签