我已經使用PHP關聯多維陣列 - 打印僅選擇鍵
exif_read_data($image, 0, true)
數組本身是從圖像拍攝的數組可以包含一個未知的數字鍵/值(也可以是0) 的在某些部分陣列也是多維的。
從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
)
)
我的問題是如何可以創建將僅顯示我選擇密鑰的功能,作爲一個鍵/值對,即使是在數組的第二維或第三維?
例如 - 從上面的陣列,如果我想只選擇[ImageWidth] , [ImageLength] , [XResolution] , [GPSTimeStamp] and [GPSLatitude] ..
我將它傳遞給像功能:
$keys_array = (ImageWidth , ImageLength, XResolution, GPSTimeStamp , GPSLatitude)
然後
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
}
我已經選擇這些鍵作爲例子,因爲它們中的一些是二級的,並且一些實際上是陣列本身..
還有一個問題是,密鑰可以在理論上被複制(用戶密鑰) - (。和爲此不名義上覆制),但駐留在不同的第二級陣列
我想我需要「變平「首先,然後以某種方式」傳遞「我想要的密鑰陣列 - 但我似乎無法真正做到。
有人知道任何現成的類/功能/片段的那種事情?
你應該使用通過樹循環遞歸函數?返回的條件應該是recurisvidad作爲參數傳遞的關鍵字。 – Lobo 2012-03-28 07:20:56
嘗試遞歸... – TigerTiger 2012-03-28 07:21:20