substr in loop php isn't work

135 views Asked by At
    <?php

$str = "RP-01, Design, Clustering, RP-02, Design, RP-03, Printer, RP-04, Database, PHP , HTML , Bussiness Logic";
$result = explode(', RP-', $str);
$row = array();
for($i=0; $i<sizeof($result) ;$i++){
    if($i=0){
        $row[0]=substr($result[0],6,strlen($result[0])-1);
    }
    else{
    $row[$i]=substr($result[$i],0,4);
    }   
        //$result[$i] = $w ;
}
?>

It's always happened Fatal error: Maximum execution time of 30 seconds exceeded

Anyone please give me the new coding ideas in this loop.

1

There are 1 answers

0
Louis Loudog Trottier On

Your if statement makes it so $i is always re setted to 0 so the loop run indefinitely

if($i=0){

Should read

if($i==0){

By using on = you are assigning the value of 0 to $i By using two equal == you will be checking if the value if 0, i think this is more what you want.