Tomer Touitou Tomer Touitou - 11 months ago 50
PHP Question

explode() give me Undefined offset in php

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

fore ex:


In my php scrip I write this

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

and when I run my code I get what I want +
Notice Undefined offset
on this line


Answer Source

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

    for($i=0; $i< count($array_gr);$i++){