Jump to content

Getting individual data from an array


richiejones24

Recommended Posts

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];
}





?>

Link to comment
https://forums.phpfreaks.com/topic/250731-getting-individual-data-from-an-array/
Share on other sites

$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.

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.