0

I have this array structure:

stdClass Object
(
    [carrierFsCode] => VX
    [flightNumber] => 925
    [departureAirportFsCode] => LAX
    [arrivalAirportFsCode] => SFO
    [stops] => 0
    [departureTerminal] => 3
    [arrivalTerminal] => 2
    [departureTime] => 2014-04-28T07:00:00.000
    [arrivalTime] => 2014-04-28T08:20:00.000
    [flightEquipmentIataCode] => 32S
    [isCodeshare] => 
    [isWetlease] => 
    [serviceType] => J
    [serviceClasses] => Array
        (
            [0] => F
            [1] => J
            [2] => Y
        )

    [trafficRestrictions] => Array
        (
        )

    [codeshares] => Array
        (
            [0] => stdClass Object
                (
                    [carrierFsCode] => SQ
                    [flightNumber] => 1407
                    [serviceType] => J
                    [serviceClasses] => Array
                        (
                            [0] => R
                            [1] => F
                            [2] => J
                            [3] => Y
                        )

                    [trafficRestrictions] => Array
                        (
                            [0] => Q
                        )

                    [referenceCode] => 10594616
                )

        )

    [referenceCode] => 979-1740743--
)
stdClass Object
(
    [carrierFsCode] => SQ
    [flightNumber] => 1407
    [departureAirportFsCode] => LAX
    [arrivalAirportFsCode] => SFO
    [stops] => 0
    [departureTerminal] => 3
    [arrivalTerminal] => 2
    [departureTime] => 2014-04-28T07:00:00.000
    [arrivalTime] => 2014-04-28T08:20:00.000
    [flightEquipmentIataCode] => 32S
    [isCodeshare] => 1
    [isWetlease] => 
    [serviceType] => J
    [serviceClasses] => Array
        (
            [0] => R
            [1] => F
            [2] => J
            [3] => Y
        )

    [trafficRestrictions] => Array
        (
            [0] => Q
        )

    [operator] => stdClass Object
        (
            [carrierFsCode] => VX
            [flightNumber] => 925
            [serviceType] => J
            [serviceClasses] => Array
                (
                    [0] => F
                    [1] => J
                    [2] => Y
                )

            [trafficRestrictions] => Array
                (
                )

        )

    [codeshares] => Array
        (
        )

    [referenceCode] => 979-1740743--10594616
)

And this array structure:

Array
(
    [0] => stdClass Object
        (
            [fs] => SQ
            [iata] => SQ
            [icao] => SIA
            [name] => Singapore Airlines
            [active] => 1
        )
    [1] => stdClass Object
        (
            [fs] => VX
            [iata] => VX
            [icao] => VRD
            [name] => Virgin America
            [active] => 1
        )

)

Basically what I want to do is take the first array and find its matching IATA/FS code in the second array and replace it with the ICAO code. So for example, with the first array, I want to replace the VX with VRD. I want to be able to apply the same concept to other airline/routes, too...not just VX.

If it helps, I'm getting this information from a JSON return: http://pastebin.com/2w0kQQ26

I looked into array_replace(), but because my PHP skills are almost nothing, I didn't know how to continue.

If someone can point me to the right direction, I'd appreciate it.

1 Answer 1

1

With array1 being your first array and array2 being the second array you described.

$comp_arr = array()
foreach ($array2 as $arr) {
  $comp_arr[$arr[fs]] = $arr[icao];
}

foreach($array1 as $key => $arr){
  if(array_key_exist($arr[carrierFsCode], $comp_arr){
       $array1[$key][carrierFsCode] = $comp_arr[$arr[carrierFsCode]];
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.