Jump to content

Putting characters of a string into an array


pea_1

Recommended Posts

They already are (kindof)!

 

$string = 'qwertyuiop';
echo $string{3}; // outputs e

 

depends on what you need but if you truely need a proper bonefide array..

 

$string = trim('qwertyuiop');
$length = strlen($string);
for($i=0; $i < $length; $i++)
{
if ($string{$i} != ' ')
{
  arr[] = $string{$i};
}
}

 

Note: the if statement will make sure you only have characters in the array that are NOT spaces.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.