Convert String to Array in PHP Without Explode

To Convert String to Array in PHP Without Explode we use for loop to count the number of words on the sentence. Create a blank array to store the words which we extract using a loop in PHP.

Convert String to Array in PHP Without Explode
Convert String to Array in PHP Without Explode

Here is the complete example how we Convert String to Array in PHP Without Explode,

Output:

Array
(
[0] => This
[1] => is
[2] => the
[3] => string
[4] => to
[5] => array
)

Code Explanations:

  • Here we first define the string, a blank variable, and a blank array.
  • A blank variable to store the extracted words from the defined string.
  • Blank array to store the words which we take from the word variable and convert to an array.
  • To extract the array we use for loop which loop through till the length of the string and check the spaces between the sentence.
  • After taking all word into an array we print using print_r() function to print an array which looks like the above output.

How to convert string to list in PHP

To convert string to list in PHP, we use the same as above but we use list() function. To know more about list() the function see details https://www.php.net/manual/en/function.list.php

In this process we do below steps,

  • Define a string.
  • Convert that string to an array.
  • That converted array changed to array list or simply list using PHP list() function.

Example to convert string to list in PHP

Complete code look like this,

Output:

How to convert string to list in PHP
How to convert string to list in PHP

You can check the above complete code using our code editor online, https://phpcoder.tech/php-online-editor/

If you have any doubt on this, please comment below.

Also Check:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 178

One thought on “Convert String to Array in PHP Without Explode

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort - milanobet giriş - gizabet giriş -
perabet giriş
- betkanyon giriş -

jojobet giriş

We are now accepting guest posting and creation of back-links.
This is default text for notification bar