Search code examples
phparrayscodeignitermultidimensional-arraymatrix-multiplication

Unsupported operand types (multiplication of array) codeigniter


I am trying to Multiply matrix with array in codeigniter. here's the details of array

$weight= Array ( [1] => 0.1740398414481 [2] => 0.10406921156399  )
$matrix_kr= Array ( [1] => Array ( [1] => Array ( [n] => 1 ) [2] => Array ( [n] => 3 )) [2] => Array ( [1] => Array ( [n] => 9 ) [2] => Array ( [n] => 5 ))

and heres my controller

function count_k($jk){
  $matrix_kr= $this->get_mpk($jk);
  $weight = $this->get_eigen_vector($jk);
  $mat = array();
  for ($b=1; $b <= 1; $b++) { 
    for ($k=1; $k <= $jumlahKriteria; $k++) { 
      $mat[$b] += ($matrix_kr[$b][$k]*$weight[$k]);
      print_r($mat);
    }
  }
}

whats wrong with this? the problem bcause of different size of array or anything else? and how to fix it?


Solution

  • May be $matrix_kr[$b][$k] should be $matrix_kr[$b][$k]['n']