lundi 20 avril 2015

PHP, Posted keys to my values are getting wrapped by extra single quotes on each side

I haven't seen this before when doing these actions, and can't find what's causing this unique behavior. My variables are getting extra single quotes around them, such as ''foo'' instead of 'foo'. It might make more sense to show.

Here's my input (note that it's an array, this is necessary)

<input type="text" name="item[0]['foo']" value="bar">

Here's my controller (note that I am using foreach to go through the array)

foreach ($_POST['item'] as $item) {
    var_dump($item);
}

Here's my var_dump (note the extra single quotes, and yes, they are single and not double quotes)

array (size=2)
  ''foo'' => string 'bar' (length=4)
  ''key'' => string 'value' (length=4)

Obviously we should expect it to be

array (size=2)
  'foo' => string 'bar' (length=4)
  'key' => string 'value' (length=4)

I am not using any external resources or frameworks except for twitter bootstrap CSS only. I am using php 5.5, and there are no other places where this variable is touched.

Where are these extra single quotes coming from?

Aucun commentaire:

Enregistrer un commentaire