I am getting this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: controllers/web.php
Line Number: 181
When I open the latest post on my website.
This the code from detail.php
:
<?php
// ...
$p_satu = explode(' ',$c['tanggal']);
$tgl = explode('-',$p_satu[0]);
$bulan = array('Jan','Feb','Mar', 'Apr', 'Mei', 'Jun','Jul','Ags','Sep','Okt', 'Nov','D');
?>
<p><?php echo $tgl[2]; ?></p>
<p><?php echo $bulan[($tgl[1]-1)]; ?></p>
</div>
</div>
And this web.php
:
<?php
// ...
private function cookiesetter($kode = 0){
if(!isset($_COOKIE[$kode])){
$content = $this->blog_model->GetContent("where kode_content = '$kode'")->result_array();
$result = $this->blog_model->UpdateData('content',array('counter' => ($content[0]['counter'])),array('kode_content'=>$kode));
if($result == 1){
setcookie($kode,"http://xxx.example.com", time()+3600);
Here is my guess. Update your controllers/web.php
$result = 0;
if (!empty($content[0])) {
$result = $this->blog_model->UpdateData('content',array('counter' => ($content[0]['counter'])),array('kode_content'=>$kode));
}
if ($result == 1) {
.....
}
If this doesn't fixed your error, let me know the code from this Line Number: 181 controllers/web.php
所以你的数组tgl没有索引2.你必须检查你在$ p_satu [0]中获得的值
This is a common error in array
accessing and is thrown by having an undefined offset
in an array, or rather by accessing a key=>value
pair in an array that does not exist. For example:
$array = array(
1=> 'hi',
3 => 'bye'
);
echo $array[0]; //Throws the error undefined offset since '0' is not an index in the array
To debug, I'd recommend doing a print_r()
or var_dump
on the array you are accessing with index [0]
and seeing what the contents of the array are as they are likely not what you expect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.