Jump to content

NEEP Help with This ARRAY PLEASE!!


AMERLOC

Recommended Posts

Could someone Please look at this and help me? I am trying to create a loop  for this ARRAY that is created from and XML .

 

I am able to loop through it the [AirAvailabilityReply] => Array & the [segmentList] => Array  Easy enough but the prblem is combining the results so that ie/ SegmentList's to the AvailabiltyReply.

Array
(
    [AirAvailabilityResults] => Array
        (
            [_size] => 7
            [segmentList] => Array
                (
                    [segment] => Array
                        (
                            [0] => Array
                                (
                                    [_key] => US1515
                                    [airlineCode] => US
                                    [airline] => US AIRWAYS
                                    [flightNumber] => 1515
                                    [originCityCode] => CLT
                                    [destinationCityCode] => PHX
                                    [departureDateTime] => 12/14/2009 5:50 PM
                                    [arrivalDateTime] => 12/14/2009 8:30 PM
                                    [equipmentCode] => 320
                                    [numberOfStops] => 0
                                    [originCity] => Charlotte
                                    [originStateProvince] => NC
                                    [originCountry] => US
                                    [destinationCity] => Phoenix
                                    [desintationStateProvince] => AZ
                                    [destinationCountry] => US

/////I have Shorten ed the response for this there are many [segements]////
                                )
        		)

                )

	[AirAvailabilityReply] => Array
                (
                    [0] => Array
                        (
                            [supplierType] => S
                            [RateInfo] => Array
                                (
                                    [nativeBaseFare] => 763.0
                                    [nativeTotalPrice] => 928.88
                                    [nativeCurrencyCode] => USD
                                    [displayBaseFare] => 763.0
                                    [displayTotalPrice] => 928.88
                                    [displayCurrencyCode] => USD
                                )

                            [FlightSegment] => Array
                                (
                                    [0] => Array
                                        (
                                            [segmentOutgoing] => true
                                            [segmentKey] => US1498
                                            [fareClass] => W
                                        )

                                    [1] => Array
                                        (
                                            [segmentOutgoing] => true
                                            [segmentKey] => US732
                                            [fareClass] => W
                                        )

                                    [2] => Array
                                        (
                                            [segmentOutgoing] => false
                                            [segmentKey] => US733
                                            [fareClass] => V
                                        )

                                    [3] => Array
                                        (
                                            [segmentOutgoing] => false
                                            [segmentKey] => US705
                                            [fareClass] => V
                                        )

                                )

                            [tripType] => R
                            [ticketType] => E
                        )
/////I have Shortened the response for this as mentioned above////
	)
         [cacheKey] => -7745a2a2:1238154267e:60e9
            [cacheLocation] => 10.186.168.48:7303
        )

)

 

 

 

This is What I have done so far but I may be trying to go at this completely Wrong:

///Loop for the AVAILABILTY LIST////////////
for ($row = 0; $row < $num; $row++)
{
foreach($avail[$row]["RateInfo"]as $nameR=>$resR){
	echo $row.">";
	echo $nameR.">";
	echo $resR."<br>";
	}
	foreach($avail[$row]["FlightSegment"] as $list){
		foreach($list as $namef=>$resf){
			echo $namef.">";
			echo $resf."<br>";

				}
			} 
}

 

Now I need to Associate the Correct Segment with the FlightSegment.

 

Anyone have any ideas?

 

Thanking you in advance!!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/173063-neep-help-with-this-array-please/
Share on other sites

sorry I don't really understand your question.

you want to match a certain Segment (say Segment[0] ) with a FlightSegment ?

how do you decide the match between the Segment and the FlightSegment ?

 

Hi again.

 

Each Segment has a Key like this example ->

 

Segment[0][_key] => US1515

 

This Key is is also used in the AirAvailabilityReply

 

[AirAvailabilityReply][0][FlightSegment][3][segmentKey] ->US1515

 

For Example: 

[AirAvailabilityReply]=> Array
                              [supplierType]
                              [RateInfo] => Array
                                         [nativeBaseFare] => 763.0
                                         [nativeTotalPrice] => 935.88
                                         [nativeCurrencyCode] => USD
                                         [displayBaseFare] => 763.0
                                         [displayTotalPrice] => 935.88
                                         [displayCurrencyCode] => USD

                              [FlightSegment] => Array
                                            [segmentOutgoing] => true
                                            [segmentKey] => US1515 ***Here is the Segment Key
                                            [fareClass] => W

                              [tripType] => R
                              [ticketType] => E

 

Then in my Segment List Array I have

[segmentList] => Array
                (
                    [segment] => Array
                        (
                            [0] => Array
                                (
                                    [_key] => US1515 ** AND HERE IS THE SEGEMENT KEY
                                              more info............
                            [1] => Array
                                (
                                    [_key] => US1515
                                              more info............


 

Basically I am trying to figure out how to create a relation between each AirAvailabilityReply and the Segement. The AirAvailabilityReply contains the Rate info etc and then the Segment contains the actual Flight inf. So each time I do the Loop for AirAvailabilityReply I would like it to check each Segment and printthe correct Segment Details for each Flight Segment.

 

Man I hope someone can help me out. I have been trying to do this for 3 days nows. I am too new to Arrays!!

 

OK GUYS Problem Solved. LOLZ I found it by declaring a a variable and using an if statement in my foreach statement!! OUF! Now I I have to Format the Results and that another story lolz.

 

For those interested here is the complete loop .

 

$segment = $responseData["AirAvailabilityResults"]["SegmentList"]["Segment"];
$avail = $responseData["AirAvailabilityResults"]["AirAvailabilityReply"];

///Testing My Array Loop FOREACH//////////


$num2=count($segment);
echo "There are".$num2."available Flights.<br>";

$num=count($avail);
echo "There are ".$num." AirAvailabilityReply.<br>";




///Loop for the AVAILABILTY LIST////////////
for ($row = 0; $row < $num; $row++)
{
foreach($avail[$row]["RateInfo"]as $nameR=>$resR){
	echo $row.">";
	echo $nameR.">";
	echo $resR."<br>";
	}
	foreach($avail[$row]["FlightSegment"] as $list){
		foreach($list as $namef=>$resf){
			$j=$resf;
			echo $row.">";
			echo $namef.">";
			echo $resf."<br>";
			/////Adding Segment info This where I had all the problems///////

			for ($row2 = 0; $row2 < $num2; $row2++){				
				foreach($segment[$row2] as $names=>$ress){

					if ($segment[$row2]["_key"] === $j){ ///Testing to see if Segement _key matches FlightSegment value
					echo $row.">";
					echo $names.">";
					echo $ress."<br>";}

							}                  
					} 

			////TESTING END//////
			}
	} 
}

 

Well if anyone knows a better and more secure way of doing this please let me know.

 

Cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.