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

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.