_FILES array

An <input type="file" name="foo"> produces this

<?php
array (
 
'foo' =>
  array (
   
'name' => '',
   
'type' => '',
   
'tmp_name' => '',
   
'error' => 4,
   
'size' => 0,
  ),
)
?>

$_FILES array. What do you think foo[bar] will produce?

<?php
array (
 
'foo' =>
  array (
   
'name' =>
    array (
     
'bar' => '',
    ),
   
'type' =>
    array (
     
'bar' => '',
    ),
   
'tmp_name' =>
    array (
     
'bar' => '',
    ),
   
'error' =>
    array (
     
'bar' => 4,
    ),
   
'size' =>
    array (
     
'bar' => 0,
    ),
  ),
)
?>

Comments

I don't get it. You mean

I don't get it. You mean dumping $_FILES['foo']['bar'] will print that?

No, <input type="file"

No,

<input type="file" name="foo[bar]">

and

<?php
var_dump
($_FILES);
?>

will print that. And it's one of the strangest "design decisions" in PHP.

The "design decision" is to

The "design decision" is to code like this....

$_FILES['foo']['name']['bar'];

But I think that $_FILES['foo']['bar']['name'] would be better...

I don't know where to submit

I don't know where to submit a solution but here you go; What is the output of this and why?

<?php
for ($i = 0; $i < 5; ++$i) {
    if (
$i == 2)
        continue
    print
"$i\n";
}
?>

The output is: 2 Your code is

The output is:
2

Your code is equivalent to:

<?php
for ($i = 0; $i < 5; ++$i) {
    if (
$i == 2) {
        continue print
"$i\n";
    }
}
?>

From http://ru.php.net/manual/en/control-structures.continue.php:
continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.

From http://ru.php.net/manual/en/function.print.php:
Print returns 1, always.

That's explains such kind of behavior :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options