␡
- Accessing All Elements of Numeric Arrays
- Accessing All Elements of Associative Arrays
- Accessing All Array Elements in Nested Arrays
- Turning an Array into Variables
- Converting Strings to Arrays
- Converting Arrays to Strings
- Sorting Arrays Alphabetically
- Sorting Associative Arrays Alphabetically
- Sorting Nested Arrays
- Sorting Nested Associative Arrays
- Sorting IP Addresses (as a Human Would)
- Sorting Anything
- Sorting with Foreign Languages
- Applying an Effect to All Array Elements
- Filtering Arrays
- Getting Random Elements Out of Arrays
- Making Objects Behave Like Arrays
This chapter is from the book
Converting Strings to Arrays
$a = explode(',', $csvdata);
<?php $csvdata = 'Pearson Education,800 East 96th Street,Indianapolis,Indiana,46240'; $a = explode(',', $csvdata); $info = print_r($a, true); echo "<pre>$info</pre>"; ?>
Turning a String into an Array (explode.php)
Sometimes, arrays are not used to store information; instead, a string is used. The single values are all within the string, but are separated by a special character. One example for this is the comma-separated values (CSV) format.
The PHP function explode() creates an array out of these values; you just have to provide the characters at which the string needs to be split. The browser then shows this output:
Array ( [0] => Pearson Education [1] => 800 East 96th Street [2] => Indianapolis [3] => Indiana [4] => 46240 )