Tomer Touitou Tomer Touitou - 17 days ago 6
PHP Question

explode() give me Undefined offset in php

What is wrong with my funky code?
I post using ajax a string

fore ex:

309534368.gif,400559388.jpg,859954067.jpg,821646469.jpg

In my php scrip I write this

$gr = preg_replace('#[^a-z0-9-,.]#i', '', $_POST['gr']);
$array_gr = explode(',',$gr);
if(count($array_gr)>=1){
for($i=0;$i<= count($array_gr);$i++){
$corentimg=$array_gr[$i];
......


and when I run my code I get what I want +
Notice Undefined offset
:
on this line
$corentimg=$array_gr[$i];


Why?

Answer

There is if condition error with your code Replace <= with <.

    for($i=0; $i< count($array_gr);$i++){
         $corentimg=$array_gr[$i];
............
Comments