How can I create a variable which is the sum of multiple numbers?

I would like to create a variable which is the sum of multiple (range-field) numbers and then echo it afterwards:

<?php $sum = $page->firstNumber() + $page->secondNumber() + $page->thirdNumber() ?>
<p>
   The sum is: <?php echo $sum ?>
</p>

But it does not work – what am I doing wrong?

Here is my blueprint setup:

      firstNumber:
        label: First Number
        type: range
        step: 1
        min: 1
        max: 5
        tooltip:
          after: /5
      secondNumber:
        label: Second Number
        type: range
        step: 1
        min: 1
        max: 5
        tooltip:
          after: /5
      thirdNumber:
        label: Third Number
        type: range
        step: 1
        min: 1
        max: 5
        tooltip:
          after: /5

Thanks in advance for any help. :slight_smile:

You have to convert the field object to an integer first:

$sum = $page->firstNumber()->toInt() + $page->secondNumber()->toInt() + $page->thirdNumber()->toInt();

Thank you so much @texnixe for your fast answer, that solved my problem! :slight_smile: