Reply to Re: string to array

Your name:

Reply:


Posted by ZeldorBlat on 06/19/07 15:58

On Jun 19, 9:12 am, Joe Scylla <joe.scy...@gmail.com> wrote:
> ana wrote:
> > please help me with converting string to an array:
>
> > I have a number for example 3567 that I wish to convert to an array for
> > example $arr=(3,5,6,7)
>
> > I have seen in PHP manual that there is str_split function, but when I write
> > it in my Dreamweaver he does not recognize it like a function and it's not
> > working when I put on web. Is there some other function?
>
> function str_to_array($v)
> {
> return preg_split('//', $v, -1, PREG_SPLIT_NO_EMPTY);
> }
>
> $x = str_to_array(1234);
>
> Result:
> Array
> (
> [0] => 1
> [1] => 2
> [2] => 3
> [3] => 4
> )

It's worth noting that you can also address individual characters in a
string like an array:

$str = '3567';
echo $str{2};

will output '6'.

If you really needed it to be an array then you could do something
like this:

function str_to_array($str) {
$a = array();
$len = strlen($str);

for($i = 0; $i < $len; $i++)
$a[$i] = $str{$i};

return $a;
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация