Jump to content

multi-field array


hansford

Recommended Posts

Hi people

 

I need a way to loop through an array where $imgid is some random number assigned to each array element and there are 4 fields id, url, tnurl, caption per array element. I need to extract these 4 fields in the same loop iteration. Thanks

 

$_SESSION['imagegallery'][$imgid]['id'];
$_SESSION['imagegallery'][$imgid]['url'];
$_SESSION['imagegallery'][$imgid]['tnurl'];
$_SESSION['imagegallery'][$imgid]['caption'];

example:

$_SESSION['imagegallery'][347]['id'];
$_SESSION['imagegallery'][347]['url'];
$_SESSION['imagegallery'][347]['tnurl'];
$_SESSION['imagegallery'][347]['caption'];
$_SESSION['imagegallery'][892]['id'];
$_SESSION['imagegallery'][892]['url'];
$_SESSION['imagegallery'][892]['tnurl'];
$_SESSION['imagegallery'][892]['caption'];

Link to comment
Share on other sites

$_SESSION['imagegallery'] is an array of arrays. You can use array functions to iterate over it and get the key/inner array -

 

foreach($_SESSION['imagegallery'] as $key=>$array){
echo "Key: $key, ID: {$array['id']}, URL: {$array['url']}, TNURL: {$array['tnurl']}, Caption: {$array['caption']}<br />";
}

Link to comment
Share on other sites

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.