richiejones24 Posted November 8, 2011 Share Posted November 8, 2011 I am having problems displaying individual data I am using $filename[0] to display the first data, any ideas where i am going wrong. <?php $active_keys = array(); foreach($_POST['img'] as $key => $filename) { if(!empty($filename)) { $active_keys[] = $key; } echo "". $filename[1]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/250731-getting-individual-data-from-an-array/ Share on other sites More sharing options...
micah1701 Posted November 8, 2011 Share Posted November 8, 2011 is $_POST['img'] an array? Quote Link to comment https://forums.phpfreaks.com/topic/250731-getting-individual-data-from-an-array/#findComment-1286382 Share on other sites More sharing options...
richiejones24 Posted November 8, 2011 Author Share Posted November 8, 2011 yes it is Quote Link to comment https://forums.phpfreaks.com/topic/250731-getting-individual-data-from-an-array/#findComment-1286385 Share on other sites More sharing options...
richiejones24 Posted November 8, 2011 Author Share Posted November 8, 2011 if i use $filename by itself i can everything in the array is i know it is working but when i use $filename[0] i get nothing Quote Link to comment https://forums.phpfreaks.com/topic/250731-getting-individual-data-from-an-array/#findComment-1286386 Share on other sites More sharing options...
xyph Posted November 8, 2011 Share Posted November 8, 2011 $filename is only supposed to be a temporary holder for each value of $_POST['img'] while looping through it. After the loop, $filename will hold the last value of $_POST['img']. If that's not an array, $filename[1] will output the 2nd character of the last value of $_POST['img']. Since I'm not sure what you're trying to do, I can't help you. My guess is, you wanted this $_POST['img'][ $active_keys[0] ] That will return the first populated value of $_POST['img], assuming it exists. Quote Link to comment https://forums.phpfreaks.com/topic/250731-getting-individual-data-from-an-array/#findComment-1286394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.