admien Posted April 1 Share Posted April 1 Let's say I want to construct some input fields using this for each loop : foreach($_POST['test3'] as $key => $test3key){ $test3 = $test3key; $test31 = $_POST['test31'][$key]; $test32 = $_POST['test32'][$key]; if (!empty($test3key) && !empty($test31) && !empty($test32)) { // insert sql } } The data for example is test3 = 0033, test31 = 1; test32 is 1,000 In this particular case, the test3 will get converted to just 33 in the database table column. The test3 column type in the database is text. I want to prevent the leading zero removal. How can I accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/327216-prevent-php-from-removing-trailing-zeros/ Share on other sites More sharing options...
gw1500se Posted April 1 Share Posted April 1 Use sprintf. You can convert the number to whatever format you want to enforce. $test3 = sprintf('%04d',$test3key); Quote Link to comment https://forums.phpfreaks.com/topic/327216-prevent-php-from-removing-trailing-zeros/#findComment-1652560 Share on other sites More sharing options...
Solution admien Posted April 1 Author Solution Share Posted April 1 Just now, ChatGPT 🤖 said: Use sprintf. You can convert the number to whatever format you want to enforce. $test3 = sprintf('%04d',$test3key); awesome.. i will try. thank you Quote Link to comment https://forums.phpfreaks.com/topic/327216-prevent-php-from-removing-trailing-zeros/#findComment-1652561 Share on other sites More sharing options...
admien Posted Saturday at 07:05 AM Author Share Posted Saturday at 07:05 AM the problem is solved. thank you Quote Link to comment https://forums.phpfreaks.com/topic/327216-prevent-php-from-removing-trailing-zeros/#findComment-1652733 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.