Klanestro
Klanestro

Reputation: 3215

matching the individual words from array

// I am working on matching the individual words from array $frequency // to the search results from that individual word.

I don't know why this does not work

for ($i = 1; $i <= ($frequency); $i++) {

    echo $i;


    echo getphp_AlexVortaro ($frequency[$i]);
    echo getphp_Smartfm($frequency[$i]);
    print_r($frequency[$i]);


}

I get

Notice: Undefined offset: 11 in /Users/briancarpenter/Sites/Vortoj/countplus.php

on line 21

X A lot

Upvotes: 0

Views: 186

Answers (2)

Vanessa MacDougal
Vanessa MacDougal

Reputation: 992

PHP array subscripts start at 0, not 1. You want your loop to be

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

Upvotes: 3

John Kugelman
John Kugelman

Reputation: 361565

Two things: (1) Arrays are 0-based, not 1-based. (2) Your conditional needs to use the count() function.

for ($i = 0; $i < count($frequency); $i++)

Upvotes: 1

Related Questions