【发布时间】:2012-04-11 18:25:39
【问题描述】:
我有一个使用
从图像中获取的数组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
}
我选择了这些键作为示例,因为它们中的一些位于第二级,而有些实际上是数组本身..
还有一个问题是理论上可以复制密钥(用户密钥)-但驻留在不同的二级数组中(因此名义上不复制。)
我想我需要先“压平”它,然后以某种方式“传递”一组我想要的键 - 但我似乎无法真正做到正确。
有人知道这类事情的任何现成的类/函数/sn-p吗?
【问题讨论】:
-
您应该使用递归循环遍历树的函数。返回它的条件应该位于 recurisvidad 作为参数传递的键。
标签: php multidimensional-array key-value flatten