Uncaught ReferenceError: button_function is not defined at HTMLButtonElement.onclick

In the heading of page.php, I’m adding include('range.php'); withrange_function(); inside, which successfully returns an array. In page.php I’m using foreach loop to generate buttons from this array values:

 $arr = range_function();
 foreach ($arr as $item) {
    ?>
    <button onclick="button_function($item)"><?= $item ?> </button>
    <?PHP
 } 

to display the name of value with the button and pass it to another function:

function button_function($input) {
  /// ...
}

Then I get the error:

page.php?title=category1:124 Uncaught ReferenceError: button_function
is not defined
at HTMLButtonElement.onclick (page.php?title=category1:124:101) onclick @ page.php?title=category1:124