Jump to content

Recommended Posts

I have an array ( $exifdata ) which contains the relevant bits that I require, read from exif data, as in the var_dump below.

 

array

  0 => string 'Caption' (length=7)

  1 => string 'Copy' (length=4)

  2 => string 'Camera' (length=6)

  3 => string 'Shutter' (length=7)

  4 => string 'fNo' (length=3)

  5 => string 'ISO' (length=3)

  6 => string 'Date' (length=4)

  7 => string 'Time' (length=4)

  'copy' => string 'Alf Thomas' (length=10)

  'caption' => string 'Blue Sky over Auld Reekie' (length=25)

  'camera' => string 'Canon PowerShot G9' (length=18)

  'shutter' => string '1/800' (length=5)

  'fNo' => string 'f/5.6' (length=5)

  'iso' => int 200

  'date' => string '07:10:2011' (length=10)

  'time' => string '09:05:26' (length=8

 

What I am trying to do is echo each key followed by its relevant data, and thought something like this would work:-

 

foreach( $exifdata as $key => $value){
echo "$key :, $value <br />";
}

 

The output I get from the above is as below:-

 

0 :, Caption

1 :, Copy

2 :, Camera

3 :, Shutter

4 :, fNo

5 :, ISO

6 :, Date

7 :, Time

copy :, Foucquet

caption :, Blue Sky over Auld Reekie

camera :, Canon PowerShot G9

shutter :, 1/800

fNo :, f/5.6

iso :, 200

date :, 07:10:2011

time :, 09:05:26

 

Which more or less does what I want except that what I actually would like is this:-

 

Copy - Foucquet

Caption - Blue Sky over Auld Reekie

Camera - Canon PowerShot G9

Shutter - 1/800

fNo - f/5.6

ISO - 200

Date - 07:10:2011

Time - 09:05:26

 

What I can't quite understand is why I am getting the two lists as an output, which simply seems to be identical to the output of the var_dump.

Link to comment
https://forums.phpfreaks.com/topic/249830-echo-array-key-with-its-relevant-data/
Share on other sites

I see that now that you point it out, what it should be is an associative array with no numerical keys at all, I have obviously done something stupid here:-

 

$exifdata = array('Caption', 'Copy', 'Camera', 'Shutter', 'fNo', 'ISO', 'Date', 'Time');

//>> Populate $exifdata
if (array_key_exists('Copyright', $exif)) {
    $exifdata['copy'] = $exif['Copyright'];
}
else {
  $exifdata['copy'] = "Foucquet";
}

$exifdata['caption'] = $exif['COMMENT'][0];
$exifdata['camera'] = $exif['Model'];
$exifdata['shutter'] = $exif['ExposureTime'];
$exifdata['fNo'] = $exif['COMPUTED']['ApertureFNumber'];
$exifdata['iso'] = $exif['ISOSpeedRatings'];
$exifdata['date'] = $date;
$exifdata['time'] = $time;

 

but am not quite sure what at this point - any ideas?

This line

$exifdata = array('Caption', 'Copy', 'Camera', 'Shutter', 'fNo', 'ISO', 'Date', 'Time');

is creating the numerical keys with those values assigned. With the rest of your code in place you can just replace that line with

$exifdata = array();

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.