i am using codeigniter, and i am declaring a variable array, i used the array and it worked fine, but php keep showing some error that does't affect the program. anyone know what's happen ?? this is my code :
view :
<?php
$banyak = 0;
$id = $results->id;
$barangNama = $results->nama;
$barangHarga = $results->harga;
$barangGambar = $results->gambar; //resulting string "1.jpg,2.jpg,3.jpg,4.jpg"
$s = 0;
//declare variable array
$newGambar = array();
for ($i = 0; $i < strlen($barangGambar); $i++) {
if ($barangGambar[$i] == ',') {
$s++;
} else {
/* here is line 90 */ $newGambar[$s] .= $barangGambar[$i];
}
}
print_r($newGambar);
?>
<?php
$w = 0;
for ($i = 0; $i <= $s; $i++) {
if ($w % 4 == 0) {
$banyak++;
}
$w++;
echo $banyak;
?>
<div class="item <?php if ($i == 0) {
echo "active";
} ?>" data-thumb="<?php echo $banyak - 1; ?>">
<img src="<?php echo base_url(); ?>assets/images/product_picture/<?php echo $newGambar[$i]; ?>">
</div>
<?php
}
?>
what i want to achieve is divided $barangGambar each coma, and input to $newGambar[0] = 1.jpg $newGambar[1] = 2.jpg and so on
but i have to loop to decide how many picture that provided
this is error msg :
A PHP Error was encountered Severity: Notice Message: Undefined offset: 0 Filename: webView/webProductZoomed.php Line Number: 90