Update example.php

Updated code to fix some basic coding mistakes and also ensure that the `k` parameter is passed before any checks are made.