How to convert a string to an array of it's characters in PHP?

PHP: How to convert a string to an array of it's characters in PHP?

If you want to get an array of (single) letters from a string, it is easy in PHP! Here is how to do it:

Use str_split() to get a text string's characters as an array

  1. $input = "asdfgh";
  2.         $array = str_split($input); // ['a','s','d','f','g','h']

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to convert a string to an array of it's characters in PHP?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the PHP language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to find the average value of items in a Laravel Collection?

How to block IP addresses in Apache by using regular expressions (regex) in .htaccess

How to set the timezone to UTC in .htaccess

What are the main error types in PHP

How to eager load multiple levels of relationships in Eloquent?

How to show a specific view file for certain error codes?

How to find the intersection (same values) from two arrays?

How to block IPv6 IP addresses in .htaccess

How to set the Expires header in .htaccess

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?