Hi, everyone
I am in a problem that
assume
variable a=“123”
I want to keep 1 2 3 in different variable as like
a[0]=1
a[1]=2
a[2]=3
Any idea will be very helpful to me.
Hi, everyone
I am in a problem that
assume
variable a=“123”
I want to keep 1 2 3 in different variable as like
a[0]=1
a[1]=2
a[2]=3
Any idea will be very helpful to me.
First divide count the number of digits
if it is 3 digits,
loop through with divide by 100, take 1 as into array with index0
next divide by 10 take 2 as into array with index1
remaing number into array with index 2
Can you explain more sir kb18001.
My input may be unknown and also may be like this
a=00111100011
Hello,
you can do it in this way:
$var = '12301245675';
$arr = array();
for ($i = 0; $i < strlen($var); $i++){
$arr[] = $var[$i];
}
echo '<pre>';
print_r($arr);
The output will be:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 0
[4] => 1
[5] => 2
[6] => 4
[7] => 5
[8] => 6
[9] => 7
[10] => 5
)
Thank you sir,
After trying i will reply u.
Check out [fphp]str_split[/fphp].
Not withstanding the solutions already posted, just to say that you already can easily access each char in a string.
$a="123"
echo $a[1] // 2
This might be helpful if the length of $a is set and importantly, is $a actually a string ‘123’ or is it an int 123 (else cast it to a string with)
$a = (string) 123;
Man page on strings might be helpful to you too.
Wandering off the topic a bit here, but pay particular attention if these numbers/string start with a 0 (zero) and you use them as integers later in your programme.