Convert string to array php
how to convert a string in array in php i.e Show
should be like this
The
asked Mar 5, 2011 at 12:59
1 Use explode function
The first argument is delimiter
answered Mar 5, 2011 at 13:02
deceze♦deceze 497k81 gold badges719 silver badges867 bronze badges 0 try json_decode like so
answered May 23, 2017 at 4:46
2 Take a look at the explode function.
answered Mar 5, 2011 at 13:04
CodemwnciCodemwnci 53.1k10 gold badges96 silver badges129 bronze badges
Zeeshan 1,65912 silver badges16 bronze badges answered Mar 26, 2014 at 6:53
RavindraRavindra 1,8413 gold badges16 silver badges20 bronze badges 1 explode() might be the function you are looking for
answered Mar 5, 2011 at 13:03
AndreasAndreas 5,2774 gold badges40 silver badges59 bronze badges There is a function in PHP specifically designed for that purpose, One benefit
of this function over
answered May 27, 2015 at 14:41
DanijelDanijel 12.1k4 gold badges36 silver badges54 bronze badges explode — Split a string by a string Syntax :
Example :
In your example :
answered Aug 15, 2018 at 12:59
Amitesh BhartiAmitesh Bharti 11.8k6 gold badges57 silver badges54 bronze badges You can achieve this even without using explode and implode function. Here is the example: Input:
Code:
Output:
answered Jan 30, 2018 at 10:57
1 here, Use explode() function to convert string into array, by a string click here to know more about explode()
Output :
it is same as the requirements:
answered May 21, 2018 at 12:09
Gautam RaiGautam Rai 2,3552 gold badges19 silver badges31 bronze badges 1 Can you convert a string to an array?We can convert a String to a character array using either a naive for loop or the toCharArray() method. To convert a string to a string array based on a delimeter, we can use String. split() or Pattern.
How do I convert a string to an array of elements?Approach:. Convert the given string into set of string.. Now create an empty string array.. Convert the string set to Array of string using set. toArray() by passing an empty array of type string.. Print the array of string.. How do I convert a string to PHP?Answer: Use the strval() Function
You can simply use type casting or the strval() function to convert an integer to a string in PHP.
What does array () do in PHP?An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. To create an array in PHP, we use the array function array( ) . By default, an array of any variable starts with the 0 index.
|