+ 1

Help me in converting string to array in PHP

I want to convert a string into an array without using any functions like explode(), mb_strlen(), strlen(). By only using loop and conditional statements. Input will be like "Hello world" Expected output [0]=>Hello [1]=>world

10th Dec 2020, 7:11 PM
Sparsh Nigam
Sparsh Nigam - avatar
4 odpowiedzi
+ 3
You can use this code. I didn't use even the strlen(). However, I should have used the empty() built-in function. https://code.sololearn.com/wa21a22A46a2
12th Dec 2020, 8:50 PM
Amir Mojiri
Amir Mojiri - avatar
+ 2
Splits the string into character array and use `count()` to get length. (Edit) Modified by removing array(), count(), str_split(), and unset() https://code.sololearn.com/wCFEXlVre14G/?ref=app
13th Dec 2020, 1:25 AM
Ipang
+ 1
Thanks for your good code. But I think the idea is not using any built-in function.
13th Dec 2020, 7:42 AM
Amir Mojiri
Amir Mojiri - avatar
+ 1
Now it's fixed without built-in function.
13th Dec 2020, 8:38 AM
Ipang