⊗ppPmBsDS 44 of 447 menu

Numbers in a String in PHP

As you already know, strings can consist of digits. In this case, everything will work similarly:

<?php $str = '12345'; echo $str[0]; // will output '1' echo $str[1]; // will output '2' echo $str[2]; // will output '3' ?>

You can, for example, find the sum of the first two digits of our number and it will work:

<?php $str = '12345'; echo $str[0] + $str[1]; // will output 3 ?>

Given a string '12345'. Find the sum of the digits of this string.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline