The reason is that salt is part of the hash output that crypt provides.
$2y$09$anexamplestringforsale/.K.VdgECUVEd9N4ja3u1WtgPi5BXZq
This is broken down into several components:
2y - algorithm identifier (bcrypt)09 - cost parameteranexamplestringforsale - salt/.K.VdgECUVEd9N4ja3u1WtgPi5BXZq - hash
This leads to a good property to simply use the hash of the result directly as a salt in the test call.
$hash = crypt($password, $salt);
if ($hash === crypt($password, $hash)) {
, . . .
, API , : password_hash().