【发布时间】:2015-03-21 06:56:51
【问题描述】:
我将在我的代码中查看 php 错误,这会导致 $time 和 $date 数组出现两个错误。 Php 说 Message: Undefined offset: 1 and 2 for both $time 和 $date。
所以我完成explode() 之后的键是未定义的吗?这到底是怎么回事?为什么?我该如何解决这个问题?使用 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;
}
}
** 错误 **
遇到了 PHP 错误
严重性:通知
消息:未定义的偏移量:1
文件名:libraries/Sweph.php
行号:61
遇到了 PHP 错误
严重性:通知
消息:未定义的偏移量:2
文件名:libraries/Sweph.php
行号:61
遇到了 PHP 错误
严重性:通知
消息:未定义的偏移量:1
文件名:libraries/Sweph.php
行号:61
遇到了 PHP 错误
严重性:通知
消息:未定义的偏移量:2
文件名:libraries/Sweph.php
行号:61
更新:忘了提到数组有来自数据库的结果并添加了错误。
【问题讨论】:
-
哪个文件在视图或控制器内部导致错误。写完整的错误消息。
-
更新了问题,codeigniter 的自定义库。
-
如果你的两个数组都有值,它不应该产生错误。很难产生场景。爆炸后尝试
echo $time[2];die();。是否再次产生错误?
标签: php codeigniter undefined