从 CodeIgniter 中的 post 数组获取数据 [英] Getting data from post array in CodeIgniter
问题描述
好的,所以我有一个表单在 POST 数组中向我发送数组.我正在尝试像这样阅读它:
Ok, so I have a form that is sending me arrays in the POST array. I am trying to read it like so:
$day = $this->input->post("days")[0];
这不起作用.PHP 说意外的 '['".为什么这不起作用?
This does not work. PHP says "unexpected '['". Why does this not work?
我通过这样做修复了它:
I fixed it by doing it this way:
$days = $this->input->post("days");
$day = $days[0];
我解决了我的问题,我只是好奇为什么第一种方法不起作用.
I fixed my problem, I'm just curious as to why the 1st way didn't work.
推荐答案
PHP 不支持从函数调用中取消引用数组.它是在 PHP 的 SVN 主干版本中实现的,因此它很可能会进入 PHP 的未来版本.现在你将不得不诉诸于你现在正在做的事情.对于枚举数组,您还可以使用 list
:
Array derefencing from function calls isn't supported by PHP. It's implemented in the SVN trunk version of PHP, so it will likely make it into future versions of PHP. For now you'll have to resort to what you're doing now. For enumerated arrays you can also use list
:
list($day) = $this->input->post("days");
这篇关于从 CodeIgniter 中的 post 数组获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!