This is a possible answer:

Let the rank of a matrix be defined to be the maximal number of independent columns of the matrix. This is also equal to the rank of the column space of the matrix.

Refer to: Definition of rank of matrices and nullity of matrices

Suppose $A=PB$ where $P$ is invertible. Suppose columns $\{a_{i_1},...,a_{i_n}\}$ are linearly independent in $A$. Therefore if $$r_1b_{i_1}+...+r_nb_{i_n}=0,$$
then

$$r_1Pb_{i_1}+...+r_nPb_{i_n}=0,$$ which implies that
$$r_1a_{i_1}+...+r_na_{i_n}=0.$$ Hence, columns $b_{i_1},..,b_{i_n}$ are linearly independent. Since we can make the same argument for $P^{-1}A=B$, we can deduce that the rank of $A$ is equal to the rank of $B$.

Suppose $A=BQ$ where $Q$ is invertible. This implies that the column space of $A$ is a subset of the column space of $B$ as the columns of $A$ are in the column space of $B$. Since $B=AQ^{-1}$, we can deduce that the $A$ and $B$ have the same column space which implies that they have the same rank.

If $A$ and $B$ have the same dimensions, by the rank-nullity theorem (see link above), the nullity of $A$ equals the nullity of $B$.