php - Uncaught TypeError: array_key_exists() -


i want modify array of samples&lables , pass predict() function. must because want samples , labels other.xls file , store in array can fit in code. original code:

    $samples = [[5, 1, 1], [1, 5, 1], [1, 1, 5]];// array() form?     $labels = ['a', 'b', 'c'];     $classifier = new naivebayes();     $classifier->train($samples, $labels);      $classifier->predict([3, 1, 1]) //return      //other file.php     predict(array $sample){     $predictions = [];     foreach ($this->targets $index => $label) {         $predictions[$label] = 0;         foreach ($sample $token => $count) {             if (array_key_exists($token, $this->samples[$index])) {                 $predictions[$label] += $count * $this->samples[$index][$token];             }         }       } 

then modified code to:

    $samples = array("samples1","samples2", "samples3",...,"samplesn");     $labels = array("a","c","b"); 

but me error :

uncaught typeerror: array_key_exists() expects parameter 2 array, string given in

just curious kind of array [[...]] this? same normal array(..)? can me? i'm sure wrong remake array


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -