Reputation: 25
Hey guys I'm new in php and I'm trying to store the numbers from a input into a string, something like this.
let's say that the input stores the number 1234:
$input = 1234;
So I wan't to store a single digit and not the whole number in the array like:
$arr[0] = 1;
$arr[1] = 2;
$arr[2] = 3;
...
How can I do that?
Upvotes: 0
Views: 584
Reputation: 3523
$input = (string)1234;
echo $input[2];
echo will output 3 -- that is the spot in the string/pseudo array represented by the array index 2
Upvotes: 1
Reputation: 120
Maybe type casting would work. See below for sample code.
$input = 1234;
$arr = (string)$input;
for($i = 0; $i < strlen($arr); $i++) {
echo $arr[$i];
}
Upvotes: 3
Reputation: 577
http://www.php.net/manual/en/function.str-split.php
String split
$arr = str_split($input);
Upvotes: 2