Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:04:13+00:00 2026-06-01T03:04:13+00:00

I have an array that is taken from an image using exif_read_data($image, 0, true)

  • 0

I have an array that is taken from an image using

exif_read_data($image, 0, true)

The array itself can contain an unknown number of keys/values (can also be 0)
The array is also Multidimentional in some parts.

An example of an array from exif_read_data :

Array
(
    [FILE] => Array
        (
            [FileName] => f-20110129_004_pp.jpg
            [FileDateTime] => 0
            [FileSize] => 3566966
            [FileType] => 2
            [MimeType] => image/jpeg
            [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS
        )

    [COMPUTED] => Array
        (
            [html] => width="2576" height="1936"
            [Height] => 1936
            [Width] => 2576
            [IsColor] => 1
            [ByteOrderMotorola] => 0
            [ApertureFNumber] => f/2.8
            [Thumbnail.FileType] => 2
            [Thumbnail.MimeType] => image/jpeg
        )

    [IFD0] => Array
        (
            [ImageWidth] => 2576
            [ImageLength] => 1936
            [BitsPerSample] => Array
                (
                    [0] => 8
                    [1] => 8
                    [2] => 8
                )

            [Make] => Nokia
            [Model] => N900
            [Orientation] => 1
            [SamplesPerPixel] => 3
            [XResolution] => 3000000/10000
            [YResolution] => 3000000/10000
            [ResolutionUnit] => 2
            [Software] => Adobe Photoshop CS5 Windows
            [DateTime] => 2011:01:29 09:37:30
            [YCbCrPositioning] => 1
            [Exif_IFD_Pointer] => 276
            [GPS_IFD_Pointer] => 658
        )

    [THUMBNAIL] => Array
        (
            [Compression] => 6
            [XResolution] => 72/1
            [YResolution] => 72/1
            [ResolutionUnit] => 2
            [JPEGInterchangeFormat] => 978
            [JPEGInterchangeFormatLength] => 5525
        )

    [EXIF] => Array
        (
            [ExposureTime] => 1/500
            [FNumber] => 14/5
            [ExposureProgram] => 0
            [ISOSpeedRatings] => 100
            [ExifVersion] => 0210
            [DateTimeOriginal] => 2011:01:29 09:37:30
            [DateTimeDigitized] => 2011:01:29 09:37:30
            [ShutterSpeedValue] => 8/1
            [ApertureValue] => 297/100
            [LightSource] => 0
            [Flash] => 0
            [FocalLength] => 26/5
            [FlashPixVersion] => 0100
            [ColorSpace] => 1
            [ExifImageWidth] => 2576
            [ExifImageLength] => 1936
            [CustomRendered] => 0
            [ExposureMode] => 0
            [WhiteBalance] => 0
            [DigitalZoomRatio] => 1/1
            [SceneCaptureType] => 0
            [GainControl] => 0
            [Contrast] => 0
            [Saturation] => 0
        )

    [GPS] => Array
        (
            [GPSVersion] => 
            [GPSLatitudeRef] => N
            [GPSLatitude] => Array
                (
                    [0] => 22/1
                    [1] => 12937/1000
                    [2] => 0/1
                )

            [GPSLongitudeRef] => E
            [GPSLongitude] => Array
                (
                    [0] => 113/1
                    [1] => 32886/1000
                    [2] => 0/1
                )

            [GPSAltitudeRef] => 
            [GPSAltitude] => 255/1
            [GPSTimeStamp] => Array
                (
                    [0] => 9/1
                    [1] => 37/1
                    [2] => 30/1
                )

            [GPSMapDatum] => WGS-84
            [GPSDateStamp] => 2011:01:29
        )

)

My question is how can I create a function that will display only the keys that I select , as a key/value pair , even if it is in the 2nd, or 3rd dimension of the array?

for example – from the array above , if I want to select only the [ImageWidth] , [ImageLength] , [XResolution] , [GPSTimeStamp] and [GPSLatitude] ..

I would pass it to the function like :

$keys_array = (ImageWidth , ImageLength, XResolution, GPSTimeStamp , GPSLatitude) 

and then

function select_keys_from_array ($keys_array='') {  
// if $keys_array=='' then get all ..
//identify the dimension or flatten - and get only my keys and display key/value 
}

I have selected those keys as example because some of them are on a second-level, and some are actually arrays themselves ..

There is also a problem is that the keys can theoretically be duplicated (user-keys) – but residing in different second-level array (and therefor not nominally duplicated.)

I guess I will need to “flatten” it first , and then to “pass” an array of my wanted keys somehow – but I can not really seem to get it right .

Does someone knows any ready-made class / function / snippet for that sort of thing ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:04:14+00:00Added an answer on June 1, 2026 at 3:04 am

    (Disclaimer; may do wacky stuff, not fully tested — should be fine though)

    Last edit; the first one was better, as it didn’t exclude array values (such as coordinates, etc.)

    function array_by_keys_recursive(array $keys, array $array) {
        $results = array();
        foreach ($keys as $key) {
            if (isset($array[$key])) {
                $results[$key] = $array[$key];
                continue;
            }
            foreach ($array as $value) {
                if (\is_array($value)) {
                    $results = \array_replace($results,
                        \array_by_keys_recursive(array($search), $value));
                }
            }
        }
        return $results;
    }
    

    Test:

    $array = array(
        'a' => 1,
        'b' => 2,
        'c' => array(
            'd' => 3,
            'e' => 4,
        ),
        'f' => 5,
        'g' => array(
            'h' => array(
                'i' => 6,
                'j' => 7,
            ),
            'k' => 8,
        ),
    );
    
    \var_dump(\array_by_keys_recursive(array('a', 'b', 'c', 'h', 'i', 'j'), $array));
    

    Results:

    array(6) {
      ["a"]=>
      int(1)
      ["b"]=>
      int(2)
      ["c"]=>
      array(2) {
        ["d"]=>
        int(3)
        ["e"]=>
        int(4)
      }
      ["h"]=>
      array(2) {
        ["i"]=>
        int(6)
        ["j"]=>
        int(7)
      }
      ["i"]=>
      int(6)
      ["j"]=>
      int(7)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of Image URl's from that array i have displayed my
I have an array that has keys and values. For eg: Array ( [name]
I have a ImageView which shows a picture that has been taken from the
I have a method that takes an array of queries, and I need to
I have a function that takes an array of objects and I need to
I have a modified version of binary search that takes in an array in
I have a method (C++) that returns a character and takes an array of
I have an array that looks like: $fields = array( f1 => array(test), f2
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
I have an array that is a member of a structure: $self->{myArray} = [value1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.