If $opname is an array containing:
['this', 'that', 'other']
$opname is 'this'
$opname is 'that'
$opname is 'other'
The count for the array is 3, as there are three items in the array.
Your code sample is setting $totalarr to the last index number of the array.
With the mysql_num_rows code, similar behaviour is occurring there too.