?
Solved

Fatal error: Unsupported operand types

Posted on 2005-04-27
11
Medium Priority
?
8,931 Views
Last Modified: 2012-06-21
I'm trying to convert a Perl function to PHP, I get a Fatal error: Unsupported operand types on line that starts with $rank.

I think that is because $total is actually an array but not sure. I could use some help. I asked a question on how to convert entire function. But I thought a more concise question may be easier to get help on.

Thanks!!


for ($i=0;$i<6;$i++) {

     for ($judge = 0; $judge < 5; $judge++) {
          $place=$placements[$judge][$i];
          $total[$place]++;
          $sum[$place] += $place;
     }

for ($place=0;$place<6;$place++) {
       $sum += $sum[$place];
       $rank[$couple]=array($place,-$total,$sum-$total[++$place]);
       if (($total += $total[$place]) > 3) {
                                          break;
                                          }
  }

}


Function in perl is
   for my $place( 1..@couples ){
       $sum += $sum[$place];
       $rank[$couple]=[$place,-$total,$sum,-$total[++$place]], last if ($total += $total[$place]) > @placements/2;
  }
0
Comment
Question by:BrentNJ
  • 7
  • 2
  • 2
11 Comments
 

Author Comment

by:BrentNJ
ID: 13877217
Should have read $rank[$i] but same problem
0
 
LVL 9

Assisted Solution

by:AlanJDM
AlanJDM earned 880 total points
ID: 13879068
array($place,-$total,$sum-$total[++$place]) <----- problem

array() function doesn't accept parameters like that. The only parameters you can pass to the array() function is index/value pairs...

array(inde1 => value1, index1 => value2)

http://us3.php.net/manual/en/function.array.php


Alan
0
 
LVL 9

Expert Comment

by:AlanJDM
ID: 13879091
typo...

array(inde1 => value1, index1 => value2)

should be...

array(inde1 => value1, index2 => value2)

Sorry. Thats like the 5th typo Ive made today... I think it is time to take a break.



Alan


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Accepted Solution

by:
German_Rumm earned 1120 total points
ID: 13879546
Hi BrentNJ,

You problem is on the line
    $sum += $sum[$place];

You can't add to array this way. If you want to consecutively add all $sum elements, use some other variable name, like
$sum2:

$sum2 += $sum[$place];
$rank[$couple] = array($place, -$total, $sum2 - $total[++$place]);

Also, there is some possible problem: you increment $place inside loop, which is not what you want probably... Use $place + 1 instead.

AlanJDM,
you are not correct, defining array like array('element1', 'element2', 'element3') is perfectly valid.

Hope this helps!
0
 

Author Comment

by:BrentNJ
ID: 13879885
Thanks!! I'll give it a try now.
0
 

Author Comment

by:BrentNJ
ID: 13879937
I actually had the sum2 in one of my tries - same problem.

Is it OK to reference the array $total as just -$total?

Maybe perl treats $total differently.
0
 
LVL 6

Expert Comment

by:German_Rumm
ID: 13880058
BrentNJ,

oops, didn't notice it. no, you cannot reference array this way.
If you want to get sum of all $total elements you should use array_sum($total), in example

    $rank[$i] = array($place, -array_sum($total), $sum2 - $total[$place+1]);

I'm sorry if this is not what you want, I just don't understand what your script does with these numbers :-)
0
 

Author Comment

by:BrentNJ
ID: 13880861
This is what I did so far

for ($place=0;$place<6;$place++) {
       $sum2 += $sum[$place];
       $rank[$couple]=array($place,-array_sum($total),$sum2-$total[++$place]);
       $total2 += $total[$place];
       if ( $total2 > 3) {
                                          break;
                                          }
  }

I'm not sure if the $total reference in perl is total of array contents or total in array. I'll check it out.
0
 

Author Comment

by:BrentNJ
ID: 13972523
Will try again tonight.
0
 

Author Comment

by:BrentNJ
ID: 14051692
I'm stuck again. The function I am trying to convert was originally asked in

http://experts-exchange.com/Miscellaneous/Math_Science/Q_21366761.html

My perl is not as good as I thought. I don't understand all the code.

Can anyone convert to php function? Raising points.
0
 

Author Comment

by:BrentNJ
ID: 14133791
Thanks for your help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question