Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将php代码转换为数组_Php_Arrays_Codeigniter_Explode - Fatal编程技术网

将php代码转换为数组

将php代码转换为数组,php,arrays,codeigniter,explode,Php,Arrays,Codeigniter,Explode,我使用codeigniter,将两个输入作为数组发送给下面的php代码,但下面的php代码并没有将其作为数组,如何更改php代码以获取值数组 <input type="text" name="date[]"> <input type="text" name="date[]"> $date=$this->input->post('date'); $jdate=jgmdate(“Y/m/j”); 列表($year\u now,$month\u now,$day\u n

我使用codeigniter,将两个输入作为数组发送给下面的php代码,但下面的php代码并没有将其作为数组,如何更改php代码以获取值数组

<input type="text" name="date[]">
<input type="text" name="date[]">

$date=$this->input->post('date');
$jdate=jgmdate(“Y/m/j”);
列表($year\u now,$month\u now,$day\u now)=爆炸('/',$jdate,3);
列表($year、$month、$day)=分解('/',$date,3)//电话号码:97
如果($year>=$year\u now&$monthconvert\u date->JalaliToGregorian($year,$month,$day);
返回$j2g[0]。“/”$j2g[1]。“/”$j2g[2];
}否则{
返回“0”;
}
使用上述代码,我有以下错误:

遇到一个PHP错误

严重性:通知

消息:数组到字符串转换

文件名:admin/model.php

电话号码:97

-

遇到一个PHP错误

严重性:通知

消息:未定义的偏移量:2

文件名:admin/model.php

电话号码:97

-

遇到一个PHP错误

严重性:通知

消息:未定义的偏移量:1

文件名:admin/model.php

电话号码:97

在这一行运行时,$date是一个数组,而不是一个字符串。您不能分解数组。如果我正确理解您的代码,您可能希望执行以下操作:

foreach ($date as $d) {
    list($year, $month, $day) = explode('/', $d, 3);
}

并分别处理表单中提交的每个“日期”。

您需要阅读并理解错误消息:

Message: Array to string conversion (Line 97)
这意味着您正在将数组转换为字符串。这通常会产生以下字符串:
“array”

“Array”
字符串上使用该
分解
,返回以下内容:

array(1) {
  [0]=>
  string(5) "Array"
}
因此,一个包含索引
0
上的
“array”
的字符串的数组。因此:

list($year, $month, $day) = array('Array');
结果:

$year = "Array"; $month = NULL; $day = NULL;
显然这不是你想要的。我不知道你想要什么,也许是这个

list($year, $month, $day) = $date;

但可能不是,因为您编写了两个日期字段,而不是三个。请参见。

据我所见,$date已经是一个数组了

因此,您需要3个输入字段

<input type="text" name="date[]">
<input type="text" name="date[]">
<input type="text" name="date[]">

此更改有两个错误:
消息:未定义的偏移量:1
消息:未定义的偏移量:2
!我更改了此
列表($year,$month,$day)=explode('/',“Array”,3);//行号:97
日期数组=数组(1){[0]=>字符串(5)$date go}列表($year,$month,$day)=array($date_array);
它不起作用,此
$date_array=array(1){
行有错误:解析错误:语法错误,意外。我做了真的吗?那永远不会起作用。您需要一个包含三个元素(0,1,2)的数组请为您在问题开头概述的日期字段添加示例数据。我不明白您的意思,请更改我的代码。我也有同样的问题。我不明白您的意思。请对您的问题进行更改。请指定您具体要找的内容,具体是什么输入数据,哪些值被输入表单字段?
$year = "Array"; $month = NULL; $day = NULL;
list($year, $month, $day) = $date;
<input type="text" name="date[]">
<input type="text" name="date[]">
<input type="text" name="date[]">
$date = $this -> input -> post('date');

$jdate = jgmdate("Y/m/j");
list($year_now, $month_now, $day_now) = explode('/', $jdate, 3);

$year = $date[0];
$month = $date[1];
$day = $date[2];

if($year>=$year_now && $month<=12 ) {
$j2g = $this->convert_date->JalaliToGregorian($year, $month, $day);
return $j2g[0]."/".$j2g[1]."/".$j2g[2];
}else {
  return '0';
}