Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP associative multidimentional array - print only selected keys
    primarykey
    data
    text
    <p>I have an array that is taken from an image using </p> <pre><code>exif_read_data($image, 0, true) </code></pre> <p>The array itself can contain an unknown number of keys/values (can also be 0) The array is also Multidimentional in some parts.</p> <p>An example of an array from exif_read_data :</p> <pre><code>Array ( [FILE] =&gt; Array ( [FileName] =&gt; f-20110129_004_pp.jpg [FileDateTime] =&gt; 0 [FileSize] =&gt; 3566966 [FileType] =&gt; 2 [MimeType] =&gt; image/jpeg [SectionsFound] =&gt; ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS ) [COMPUTED] =&gt; Array ( [html] =&gt; width="2576" height="1936" [Height] =&gt; 1936 [Width] =&gt; 2576 [IsColor] =&gt; 1 [ByteOrderMotorola] =&gt; 0 [ApertureFNumber] =&gt; f/2.8 [Thumbnail.FileType] =&gt; 2 [Thumbnail.MimeType] =&gt; image/jpeg ) [IFD0] =&gt; Array ( [ImageWidth] =&gt; 2576 [ImageLength] =&gt; 1936 [BitsPerSample] =&gt; Array ( [0] =&gt; 8 [1] =&gt; 8 [2] =&gt; 8 ) [Make] =&gt; Nokia [Model] =&gt; N900 [Orientation] =&gt; 1 [SamplesPerPixel] =&gt; 3 [XResolution] =&gt; 3000000/10000 [YResolution] =&gt; 3000000/10000 [ResolutionUnit] =&gt; 2 [Software] =&gt; Adobe Photoshop CS5 Windows [DateTime] =&gt; 2011:01:29 09:37:30 [YCbCrPositioning] =&gt; 1 [Exif_IFD_Pointer] =&gt; 276 [GPS_IFD_Pointer] =&gt; 658 ) [THUMBNAIL] =&gt; Array ( [Compression] =&gt; 6 [XResolution] =&gt; 72/1 [YResolution] =&gt; 72/1 [ResolutionUnit] =&gt; 2 [JPEGInterchangeFormat] =&gt; 978 [JPEGInterchangeFormatLength] =&gt; 5525 ) [EXIF] =&gt; Array ( [ExposureTime] =&gt; 1/500 [FNumber] =&gt; 14/5 [ExposureProgram] =&gt; 0 [ISOSpeedRatings] =&gt; 100 [ExifVersion] =&gt; 0210 [DateTimeOriginal] =&gt; 2011:01:29 09:37:30 [DateTimeDigitized] =&gt; 2011:01:29 09:37:30 [ShutterSpeedValue] =&gt; 8/1 [ApertureValue] =&gt; 297/100 [LightSource] =&gt; 0 [Flash] =&gt; 0 [FocalLength] =&gt; 26/5 [FlashPixVersion] =&gt; 0100 [ColorSpace] =&gt; 1 [ExifImageWidth] =&gt; 2576 [ExifImageLength] =&gt; 1936 [CustomRendered] =&gt; 0 [ExposureMode] =&gt; 0 [WhiteBalance] =&gt; 0 [DigitalZoomRatio] =&gt; 1/1 [SceneCaptureType] =&gt; 0 [GainControl] =&gt; 0 [Contrast] =&gt; 0 [Saturation] =&gt; 0 ) [GPS] =&gt; Array ( [GPSVersion] =&gt; [GPSLatitudeRef] =&gt; N [GPSLatitude] =&gt; Array ( [0] =&gt; 22/1 [1] =&gt; 12937/1000 [2] =&gt; 0/1 ) [GPSLongitudeRef] =&gt; E [GPSLongitude] =&gt; Array ( [0] =&gt; 113/1 [1] =&gt; 32886/1000 [2] =&gt; 0/1 ) [GPSAltitudeRef] =&gt; [GPSAltitude] =&gt; 255/1 [GPSTimeStamp] =&gt; Array ( [0] =&gt; 9/1 [1] =&gt; 37/1 [2] =&gt; 30/1 ) [GPSMapDatum] =&gt; WGS-84 [GPSDateStamp] =&gt; 2011:01:29 ) ) </code></pre> <p>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?</p> <p>for example - from the array above , if I want to select only the <code>[ImageWidth] , [ImageLength] , [XResolution] , [GPSTimeStamp] and [GPSLatitude] ..</code></p> <p>I would pass it to the function like :</p> <pre><code>$keys_array = (ImageWidth , ImageLength, XResolution, GPSTimeStamp , GPSLatitude) </code></pre> <p>and then </p> <pre><code>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 } </code></pre> <p>I have selected those keys as example because some of them are on a second-level, and some are actually arrays themselves ..</p> <p>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.)</p> <p>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 .</p> <p>Does someone knows any ready-made class / function / snippet for that sort of thing ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload