我的代码中会查看php错误,导致$ time和$ date数组出现两个错误。 Php说消息:未定义的偏移:$ time和$ date都是1和2。
所以我完成爆炸()后的键是未定义的?这究竟是怎么回事?我该如何解决这个问题?数组显示来自数据库,我在使用print_r时可以看到。
Array ( [0] => 05 [1] => 51 [2] => 00 )
Array ( [0] => 1984 [1] => 06 [2] => 23 )
我尝试了很多东西,似乎都没有用。我不记得以前我遇到过这个问题......我几乎开始认为问题可能与Codeigniter有关吗?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sweph {
public $julian_ut = null;
public $config = array();
public $chart_id='';
public $user_id='';
public $chart_name='';
public $chart_time='';
public $chart_date='';
public $chart_search='';
public $chart_timezone='';
public $chart_houses='';
public $chart_longitude='';
public $chart_latitude='';
public $time = array();
public $date = array();
/***
* Initialize chart details
**/
public function __construct($config=array()) {
// Get instance
$this->CI =& get_instance();
// Initializes and Loads Ephemeris files from Directory
swe_set_ephe_path(FCPATH.'ephemeris');
// Creates objects from config array
foreach ($config as $property => $value)
{
$this->$property = $value;
}
// Create time and date array
$time = explode(":", $this->chart_time);
$date = explode("-", $this->chart_date);
// Calculates Julian day
$this->julian_ut = swe_julday(intval($date[0]), $date[1], $date[2], ($time[0] + $time[1] / 60 + $time[2] / 3600) , SE_GREG_CAL);
}
/***
* Return time/day in julian day number
**/
public function get_julian_ut() {
return $this->julian_ut;
}
}
&#13;
**错误**
遇到PHP错误
严重性:注意
消息:未定义的偏移量:1
文件名:libraries / Sweph.php
行号:61
遇到PHP错误
严重性:注意
消息:未定义的偏移量:2
文件名:libraries / Sweph.php
行号:61
遇到PHP错误
严重性:注意
消息:未定义的偏移量:1
文件名:libraries / Sweph.php
行号:61
遇到PHP错误
严重性:注意
消息:未定义的偏移量:2
文件名:libraries / Sweph.php
行号:61
更新:忘记提及数组包含数据库结果和添加的错误。
答案 0 :(得分:1)
检查其var_dump()
,然后相应地使用索引。
$time = explode(":", $this->chart_time);
var_dump($time);
$date = explode("-", $this->chart_date);
var_dump($date);
但这是不正确的方式来获取日期,月份或时间的过时和时间。
的推荐:强>
<?php
$date = '2015-01-22';
$time = '18:16:12';
$dt = new DateTime($date);
$tm = new DateTime($time);
$day = $dt->format('d');
$month = $dt->format('m');
$year = $dt->format('Y');
$hour = $tm->format('H');
$min = $tm->format('i');
$sec = $tm->format('s');
的演示:强>
http://3v4l.org/VDB7l
答案 1 :(得分:0)
$time = explode(":", $this->chart_time);
//it seems $time does not have value for 1,2 index
//$time[1] $time[2] does not exists
这就是你收到警告的原因
相同 $date = explode("-", $this->chart_date);
确保$ time的最小尺寸为3。如果尺寸小于3,它将产生相同的警告。