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
https://forums.phpfreaks.com/topic/231766-multi-field-array/
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
https://forums.phpfreaks.com/topic/231766-multi-field-array/#findComment-1192477
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.