How to access all array values from do_action_ref_array()?

Whether you use do_action() or do_action_ref_array(), accessing the parameters from the hook callback is just the same for both the functions. But the primary difference between them lies in the way we provide the parameters to the functions:

  • With do_action(), we simply pass each parameter individually:

    do_action( 'some_hook', 1, 2, 3, 'etc' );
    // i.e. do_action( <hook name>, <parameter>, <parameter>, <parameter>, ... );
    
  • But with do_action_ref_array(), we put each parameter into an array and then pass that array as the second parameter to do_action_ref_array():

    do_action_ref_array( 'some_hook', array( 1, 2, 3, 'etc' ) );
    /* i.e. do_action_ref_array( <hook name>, array(
        <parameter>, <parameter>, <parameter>, ...
    ) ); */
    

But despite that difference, do_action_ref_array() will actually pass each of the array items as an individual parameter to the hook callback, i.e. it does something like hook_callback( <parameter>, <parameter>, <parameter>, ... ); e.g. my_function( $args[0], $args[1] ) where my_function is the hook callback and $args is the array passed to do_action_ref_array().

// Let's say you had this:
add_action( 'my_hook', 'my_function' );

// And then this:
$args = [ 1, 2 ]; // same as $args = array( 1, 2 )
do_action_ref_array( 'my_hook', $args );

// And do_action_ref_array would make a call that's similar to:
my_function( $args[0] ); // i.e. my_function( 1 )

// But if you had this: (note the fourth parameter)
add_action( 'my_hook', 'my_function', 10, 2 );

// Then the call would be:
my_function( $args[0], $args[1] ); // i.e. my_function( 1, 2 )

So referring to your code, if you want both the 5 and 6 be available within your callback, then the callback needs to accept two parameters and tell add_action() (via the fourth parameter) to pass two parameters to the callback:

// Set the callback to accept two parameters.
function testing_ref_array( $arg1, $arg2 ) {
    var_dump( $arg1, $arg2 );
}

// And then tell add_action() to pass two parameters to the callback.
add_action( 'testing', 'testing_ref_array', 10, 2 );
// i.e. add_action( <hook name>, <callback>, <priority>, <number of accepted parameters> )

Additionally, it’s worth noting that do_action_ref_array() uses call_user_func_array() to call the hook callbacks, so how we call call_user_func_array() is also how we call do_action_ref_array(), except that the first parameter for do_action_ref_array() is the hook name and not the callback. The same context applies to do_action(), but it works more like call_user_func(), despite that do_action() also uses call_user_func_array().