dimanche 26 mars 2017

Array check undefined offset php

I'll try to explain it.

i have a array:

 $arrayTime = array(0=>"07",1=>"09", 3=>"13", 4=>"15", 5=>"17", 6=>"19");

Here you can see that is not defined offset 2 and now i need for my array and on offset 2 push number 0(for example) I tried use this:

if($arrayTime[$i]==""){
   $arrayTime[$i]=0;
}

Yes it works but 50 to 50 array looks like this:

$arrayTime = array(0=>"07",1=>"09", 3=>"13", 4=>"15", 5=>"17", 6=>"19",2=>"0");

but on the line where is the if it throws an error:

Notice: Undefined offset: 2 in C:\wamp\www\xxx.php on line 10

So i need same result, but without error. Thanks for your help all :)

Aucun commentaire:

Enregistrer un commentaire