Very simple: you are passing $numerosJ1
per copy ; that is, inside your function numerosJugadores( )
a copy of your array is arriving, no the original array; within that function you add things ... but to the copy , not the original.
The consequence of this: your original array $numerosJ1
does not change , since you are not really using it.
To solve it, simply pass it by reference (indicating it when declaring the function):
$numerosJ1 = array( );
numerosJugadores( $numerosJ1 );
function numerosJugadores( &$arreglo ) {
for( $i = 0; $i <= 5; $i++ ) {
$numero = rand( 1, 45 );
$arreglo[$i] = $numero;
echo $numero." ";
}
}
echo count( $numerosJ1 );
As you see, the only change has been that, indicate to the PHP interpreter that the function requires passing the argument as a reference:
function numerosJugadores( &$arreglo ) {
By doing so, a copy is not created, and your function works with the original array .