•  » Engine
  •  » getting IPTC data

#1 2017-08-21 02:04:04


getting IPTC data


I read through the core code to see how IPTC data was mapped, and came across this code:

File ""
function "get_iptc_data"

We have the function whose job it is to take the array of parsed IPTC data from file, extracts only the data defined in the user defined IPTC map array,  and saves the result to a new array.

There is a foreach loop which steps through array elements in the user defined IPTC map, which makes sense. But the there is an additional, nested foreach which loops through it AGAIN. Why? It seems to me that this function can be accomplished using only one loop, and that this is adding unnecessary complexity. For a map with X elements, this requires X^2 iterations (exponentially more processing time and resources).

Maybe it's a stupid question but why not simply do:

foreach ($map as $property => $code)          // step through the elements in user's IPTC mapping
  if ( isset ($iptc[$code]))                              //  does this element exist in the file's IPTC block? (ex. code "2#025")
    $result[$property] = $iptc[$code]             // save the IPTC value to appropriate property in result according to map


  •  » Engine
  •  » getting IPTC data

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate © 2002-2018 · Contact