PHP random string with random spaces

I found this code to generate a random string with random spaces, but I can’t understand how it works. I’m mainly interested in the if statement “if($sp–)”, what does it mean?

<?php
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$len = strlen($chars)-1;
$space = rand(1, 5);

for ($x = 0; $x <= 10; $x++) {
if($space--) {
   $pos = rand(0, $len);

  echo substr($chars, $pos, 1);
  
} else {
  
  echo ' ';
  $sp = rand(1, 5);

}

}