Convert a three digit integer to an array in php
Posted by Raj
How do I convert a three digit integer to an array so that each digit is in its own element?
In this article, I will show how to convert a three digit integer to an array so that each digit is in its own element.
we are using php str_split() Function.
PHP str_split() function :
The str_split() function splits a string into an array.
Syntax
str_split(string,length)
Example:
<?php
$string="123";
$arr=str_split($string);
print_r($arr);
?>
Output: Array ( [0] => 1 [1] => 2 [2] => 3 )
In this article, I will show how to convert a three digit integer to an array so that each digit is in its own element.
we are using php str_split() Function.
PHP str_split() function :
The str_split() function splits a string into an array.
Syntax
str_split(string,length)
Example:
<?php
$string="123";
$arr=str_split($string);
print_r($arr);
?>
Output: Array ( [0] => 1 [1] => 2 [2] => 3 )
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
convert integer to an array,
PHP,
PHP interview questions and answers,
splits a string into an array,
str_split()
.You can leave a response, or trackback from your own site.