39 of 110 menu

PHP Convert to Array

To split a string into an array using a specified delimiter, the explode function is used. See the example:

<?php $str = 'ab-cd-e'; $arr = explode('-', $str); var_dump($arr); ?>

Code execution result:

['ab', 'cd', 'e']

To convert a string to an array, the str_split function is used. See the example:

<?php $str = 'abcde'; $arr = str_split($str, 2); var_dump($arr); ?>

Code execution result:

['ab', 'cd', 'e']
English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline