Kenapa $i nya ga mau berubah ya dalam for?

 function ndw($term) {
$term = strtolower($term);
$doc_locations = $this->corpus_terms[$term];
$num_locations = count($doc_locations);
$docs_with_term = array();
$i=0;
for($doc_location=0; $doc_location < $num_locations; $doc_location++)
$docs_with_term[$i]++;
return count($docs_with_term);
}

avatar faizin2q
@faizin2q

1 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

2 Jawaban:

Pas baris yang ini:

 $docs_with_term[$i]++;

Bukannya seharusnya begini gan:

 $docs_with_term[$i++];
avatar devio
@devio

101 Kontribusi 46 Poin

Dipost 6 tahun yang lalu

@faizin2q itu untuk codenya kyknya ada yg kurang $i++ ? atau increase value?, jika $i mau di increase pk $i++; atau [$i++] tp itu tdk ada valuenya.

 $docs_with_term[$i]++;
$i++;
// result = all value 1;

$docs_with_term[$i++];
//result offset, no value ??

// contoh :
$i = 0;
$a[$i] = "aaa";
$a[$i]++;
echo $a[$i]; // result aab, a increase ++ a->b
// yang di increase itu valuenya bukan keynya

$a[1]++;
echo $a[1];
// error offset karena blm di set sebelumnya
// result 1, karena valuenya tidak di set yakni 0 kemudian di increase ++ sehingga 0->1

avatar blackarch
@blackarch

101 Kontribusi 35 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban