Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将真值复制到不正确的用户对象中_Php_Arrays_Object - Fatal编程技术网

Php 将真值复制到不正确的用户对象中

Php 将真值复制到不正确的用户对象中,php,arrays,object,Php,Arrays,Object,我有一个非常奇怪的问题,希望有人能帮助我。下面是正在发生的事情: 一个名为processServices的函数用于获取一个名为“flight”的大型对象,以及从上一页的表单中获取值,以将选定的航空公司服务添加到对象内相应用户的“配置文件”中。然后,它还计算该特定用户的服务总价,并将其添加到对象中 这些服务是动态的,但在这里并不是真正相关的,除了我不能期望在我的函数中有任何服务代码,而且必须依赖get数据 问题是,如果我有两个用户,而第二个用户注册了一项服务,那么第一个用户也会获得该服务,即使该用

我有一个非常奇怪的问题,希望有人能帮助我。下面是正在发生的事情:

一个名为processServices的函数用于获取一个名为“flight”的大型对象,以及从上一页的表单中获取值,以将选定的航空公司服务添加到对象内相应用户的“配置文件”中。然后,它还计算该特定用户的服务总价,并将其添加到对象中

这些服务是动态的,但在这里并不是真正相关的,除了我不能期望在我的函数中有任何服务代码,而且必须依赖get数据

问题是,如果我有两个用户,而第二个用户注册了一项服务,那么第一个用户也会获得该服务,即使该用户的服务总数保持为零

运行功能前的飞行对象示例:

[Flight] => stdClass Object
                (
                    [Adults] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [FirstName] => Test
                                    [MiddleName] => 
                                    [LastName] => Account
                                    [Services] => stdClass Object
                                        (
                                            [BLND] => 0
                                            [EMSA] => 0
                                            [PETH] => 0
                                            [SVAN] => 0
                                            [WCHR] => 0
                                        )

                                )

                            [1] => stdClass Object
                                (
                                    [FirstName] => The
                                    [MiddleName] => 
                                    [LastName] => Dude
                                    [Services] => stdClass Object
                                        (
                                            [BLND] => 0
                                            [EMSA] => 0
                                            [PETH] => 0
                                            [SVAN] => 0
                                            [WCHR] => 0
                                        )

                                )

                        )

                    [AdultNum] => 2
                    [Services] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => BLND
                                    [Description] => Can Choose Own Seat
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => 
                                    [CategoryID] => 1
                                    [SSRCode] => BLND
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 8
                                    [Refundable] => 
                                    [PNLActive] => 1
                                    [CutoffHours] => -1
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 8
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                    [Name] => Blind Passenger
                                )

                            [1] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => EMSA
                                    [Description] => 
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => Flat Fee
                                    [CategoryID] => 221
                                    [SSRCode] => EMSA
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 1
                                    [Refundable] => 1
                                    [PNLActive] => 1
                                    [CutoffHours] => 0
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 1
                                    [QuantityAvailable] => 1
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                    [Name] => Emotional Support Animal
                                )

                            [2] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => PETH
                                    [Description] => PET IN HOLD
                                    [CurrencyCode] => USD
                                    [Amount] => 25
                                    [AmountActive] => 1
                                    [AmountType] => Flat Fee
                                    [CategoryID] => 221
                                    [SSRCode] => PETH
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 1
                                    [Refundable] => 1
                                    [PNLActive] => 
                                    [CutoffHours] => 0
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 0
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                )

                            [3] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => SVAN
                                    [Description] => SERVICE ANIMAL
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => Flat Fee
                                    [CategoryID] => 221
                                    [SSRCode] => SVAN
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 1
                                    [Refundable] => 1
                                    [PNLActive] => 1
                                    [CutoffHours] => 0
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 0
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                )

                            [4] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => WCHR
                                    [Description] => 
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => 
                                    [CategoryID] => 1
                                    [SSRCode] => WCHR
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 8
                                    [Refundable] => 
                                    [PNLActive] => 1
                                    [CutoffHours] => -1
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 8
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                    [Name] => Wheelchair (can Climb Stairs And Walk To Chair)
                                )

                        )

                )
下面是函数。请注意,get数据的结构如下所示: 服务代码-#,其中代码是服务的唯一代码,#是用户id(从0开始,一直到8)。因此,如果用户1想要一只宠物在等待中,那么他将有一个类似service-PETH-0的get名称

功能:

function processServices($flight, $get) {
    $totalCost = 0;
    for($i=0; $i<$flight->AdultNum; $i++) {
        $totalCost = 0;
        foreach($flight->Services as $s) {
            $code = $s->SSRCode;
            if ($get['service-'.$code.'-'.$i] == 'yes') {
                $flight->Adults[$i]->Services->$code = true;
                $totalCost += $s->Amount;
            } else {
                $flight->Adults[$i]->Services->$code = false;
            }
        }
        $flight->Adults[$i]->ServicesTotal = $totalCost;
        $totalCost = 0;
    }

    return $flight;
}
但出于某种原因,在使用该函数进行处理后,这是新对象(PETH为两个用户标记,尽管它仅为一个用户总计):


此函数是代码中唯一修改这些值的函数。如果我将函数设置为始终将它们设置为false,则所有这些函数都将为false。有什么帮助吗?

不知道发生了什么,但我只是在函数中的for()的顶部添加了这一位,然后将服务设置为等于ServicesTest,并将其修复

foreach($flight->Services as $serv) {
    $code = $serv->SSRCode;
    $flight->Adults[$i]->ServicesTest->$code = ($get['service-'.$code.'-'.$i] == 'yes' ? true : false);
}

...

$flight->Adults[$i]->Services = $flight->Adults[$i]->ServicesTest;
[Flight] => stdClass Object
                (
                    [Adults] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [FirstName] => Test
                                    [MiddleName] => 
                                    [LastName] => Account
                                    [Services] => stdClass Object
                                        (
                                            [BLND] => 0
                                            [EMSA] => 0
                                            [PETH] => 1
                                            [SVAN] => 0
                                            [WCHR] => 0
                                        )
                                    [ServicesTotal] => 0
                                )

                            [1] => stdClass Object
                                (
                                    [FirstName] => The
                                    [MiddleName] => 
                                    [LastName] => Dude
                                    [Services] => stdClass Object
                                        (
                                            [BLND] => 0
                                            [EMSA] => 0
                                            [PETH] => 1
                                            [SVAN] => 0
                                            [WCHR] => 0
                                        )
                                    [ServicesTotal] => 25
                                )

                        )

                    [AdultNum] => 2
                    [Services] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => BLND
                                    [Description] => Can Choose Own Seat
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => 
                                    [CategoryID] => 1
                                    [SSRCode] => BLND
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 8
                                    [Refundable] => 
                                    [PNLActive] => 1
                                    [CutoffHours] => -1
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 8
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                    [Name] => Blind Passenger
                                )

                            [1] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => EMSA
                                    [Description] => 
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => Flat Fee
                                    [CategoryID] => 221
                                    [SSRCode] => EMSA
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 1
                                    [Refundable] => 1
                                    [PNLActive] => 1
                                    [CutoffHours] => 0
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 1
                                    [QuantityAvailable] => 1
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                    [Name] => Emotional Support Animal
                                )

                            [2] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => PETH
                                    [Description] => PET IN HOLD
                                    [CurrencyCode] => USD
                                    [Amount] => 25
                                    [AmountActive] => 1
                                    [AmountType] => Flat Fee
                                    [CategoryID] => 221
                                    [SSRCode] => PETH
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 1
                                    [Refundable] => 1
                                    [PNLActive] => 
                                    [CutoffHours] => 0
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 0
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                )

                            [3] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => SVAN
                                    [Description] => SERVICE ANIMAL
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => Flat Fee
                                    [CategoryID] => 221
                                    [SSRCode] => SVAN
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 1
                                    [Refundable] => 1
                                    [PNLActive] => 1
                                    [CutoffHours] => 0
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 0
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                )

                            [4] => stdClass Object
                                (
                                    [LogicalFlightID] => 4569
                                    [ServiceID] => 0
                                    [DepartureDate] => 2017-04-03T00:00:00
                                    [OperatingCarrier] => 
                                    [MarketingCarrier] => 
                                    [CodeType] => WCHR
                                    [Description] => 
                                    [CurrencyCode] => USD
                                    [Amount] => 0.0
                                    [AmountActive] => 1
                                    [AmountType] => 
                                    [CategoryID] => 1
                                    [SSRCode] => WCHR
                                    [Display] => 1
                                    [MaxCountServiceLevel] => 8
                                    [Refundable] => 
                                    [PNLActive] => 1
                                    [CutoffHours] => -1
                                    [Commissionable] => 
                                    [DisplayOrder] => 0
                                    [RevenueCategoryID] => 7
                                    [IATAStandardCodeType] => 
                                    [ServiceActive] => 1
                                    [MaxCountFlightLevel] => 0
                                    [QuantityAvailable] => 8
                                    [StartSalesDays] => -1
                                    [ApplicableTaxes] => stdClass Object
                                        (
                                        )

                                    [BoardingPassSsrOrder] => 999
                                    [Name] => Wheelchair (can Climb Stairs And Walk To Chair)
                                )

                        )

                )
foreach($flight->Services as $serv) {
    $code = $serv->SSRCode;
    $flight->Adults[$i]->ServicesTest->$code = ($get['service-'.$code.'-'.$i] == 'yes' ? true : false);
}

...

$flight->Adults[$i]->Services = $flight->Adults[$i]->ServicesTest;