Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Implementing Arrays
 
Article Index
Implementing Arrays
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
:

Listing 2.19. Using the explode() Function
<?php

$input_string = "John Coggeshall, Max Smith, Mary Johnston";

$pieces = explode(",", $input_string);

echo "Names in List: <BR/>\n";
foreach($pieces as $name) {
echo trim($name) . "<BR/>\n";
}

?>

Conversely, PHP also provides a function that will take all of the individual elements within an array and create a string from them. This function is the implode() function and has the following syntax:

implode($glue, $pieces);

$glue is the string used to "glue" each element of the array specified by $pieces together. uses this function to re-create our original string after it has been exploded:

Listing 2.20. Using the implode() Function
<?php

$input_array = array("John Coggeshall",
"Max Smith",
"Mary Johnston");

$orig_string = implode(", ", $input_array);

?>


Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Natural 204
Statistic


Last Post

 
Top! Top!