Example 1 — Check If an Algorithm Exists
Test names before you use them.
<?php
$algos = hash_algos();
echo "sha256: ", in_array('sha256', $algos, true) ? "yes" : "no", PHP_EOL;
echo "md5: ", in_array('md5', $algos, true) ? "yes" : "no", PHP_EOL;
echo "fake256: ", in_array('fake256', $algos, true) ? "yes" : "no", PHP_EOL; How It Works
- Get the list. It is a plain array of strings.
- Search with in_array(). Strict mode compares exact names.
- Real names return yes. sha256 and md5 are built in.
- Made-up names return no. Calling
hash('fake256', ...)would fail.

