Ohoud
0
Q:

explode a number php


 <?php
$str = 'one,two,three,four';
// to get all of the numbers: [one, two, three, four]
$numbers1 = explode(',',$str)
// same as $str
$numbers2 = explode(',',$str,0);
 
// breakes the string into two parts
$numbers3 = explode(',',$str,2);

// the last result will be removed
$numbers4 = explode(',',$str,-1);
?> 
 
6
$nums = ""; //Declare a variable with empty set.

$nums .= $number; //concatenate the empty string with the integer $number You can also use

$nums = $nums.$number; // this and the expression above do the same thing choose whichever you
                     //like.. This concatenation automatically converts integer to string
$nums[0] is now 4, $nums[1] is now 5, etc..
$length = strlen($nums); // This is the length of your integer.
$target = strlen($nums) -1; // target the last digit in the string;    
$last_digit = $nums[$target]; // This is the value of 5. Last digit in the (now string)
2
/*  The explode() function breaks a string into an array.

Note: The "separator" parameter cannot be an empty string.  */
syntax:
explode(separator,string,limit);

<html>
<body>
<?php
$str = 'one,two,three,four';
// zero limit
print_r(explode(',',$str,0));
print "<br>";

// positive limit
print_r(explode(',',$str,2));
print "<br>";
</body>
</html>
  
  
<output>
Array ( [0] => one,two,three,four )
Array ( [0] => one [1] => two,three,four )  
 
0

New to Communities?

Join the community