note 54851 added to function.dechex
| From: | trance4rm at osu1 dot php dot net | Date: | Sun, 17 Jul 2005 20:08:02 +0000 |
| Subject: | note 54851 added to function.dechex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92087@lists.php.net to get a copy of this message | ||
a bugfix for admin AT bobfrank DOT org' s post
The original was:
<?php
function zeropad($num, $lim)
{
return (strlen($num) >= $lim) ? $num : zeropad("0" . $num);
}
?>
I couldn't get it to work, kept getting a "Missing argument 2 for zeropad()" error,
even though I called the function with both arguments -- then I noticed the recursive part, and the
missing $lim argument. The code that works is:
<?php
function zeropad($num, $lim)
{
return (strlen($num) >= $lim) ? $num : zeropad("0" . $num, $lim); // $lim was
missing from the recursive call
// the function will prefix $num with a zero and recursively call itself
// each recursive call, $num gets one digit bigger until strlen of $num equals $lim
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.dechex.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54851
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54851&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54851&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54851&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54851&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54851&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54851&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54851&report=yes
Search -- http://master.php.net/manage/user-notes.php