up vote 0 down vote favorite
share [fb]

such as :

DEFGHIJKLMN

into array like:

$diskVolume = array('D','E','F','G','H','I','J','K','L','M','N');

Because explode() doesn't work for this kind of string.

Thank you very much!!

link|improve this question

You should check out the "See Also" suggestions in the php manual ("str_split() - Convert a string to an array"). – GZipp Jan 25 at 9:47
feedback

2 Answers

up vote 7 down vote accepted

Use str_split() to split a string into its individual characters:

$diskVolume = str_split($string);
link|improve this answer
Great! Thank you very much! – qinHaiXiang Jan 25 at 9:30
feedback

You can actually use array access to read from strings:

>> $a = 'CDEFGHIJKLMO';
'CDEFGHIJKLMO'
>> echo $a[2];
E

However you can't use it as an argument for foreach() and similar constructs/functions

link|improve this answer
Yup, because strings are not arrays. – BoltClock Jan 25 at 10:23
A good thing to know anyway. – Mchl Jan 25 at 10:30
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.