Getting index of a custom ACF block with PHP?

For those looking for a PHP solution. A good place to do this is in the render_callback function. One thing to keep in mind with this solution is that this only works on first load, which is good enough for the frontend, but it will not work accurately in the Gutenberg editor itself once you start editing and/or moving blocks.

acf_register_block_type([
  'name' => 'blockname,
  'render_callback'  => 'my_acf_block_render_callback',
]);

function my_acf_block_render_callback($block) {
  global $block_index;
  $index = $block_index++;

  // Do whatever else you need to do and make sure you pass the $data array to your template.
}