PHP and JavaScript convert strings to digital String2int

Source: Internet
Author: User

When I looked at Liaoche's JavaScript tutorial, there was a problem in that using reduce () to convert a string to int, I looked at the method posted in the comments, it was quite an accident, thought he only used a line of code, that is, the following line of code

var str= "123456"; var num=str*1;

Because JavaScript and PHP are both weakly typed languages, the same variable name can be repeatedly assigned different types of values, and then I try it again with PHP, as expected.

<?php$str= "123456"; $num = $str *1;var_dump ($num);//int (123456)?>

Have to say, this method is indeed very innovative, the same method, but also can use s-0,s+0, etc.

PHP and JavaScript convert strings to digital String2int

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.