Home  >  Article  >  Backend Development  >  implode and explode in php

implode and explode in php

巴扎黑
巴扎黑Original
2016-11-12 14:27:221799browse

I encountered a lot of problems when developing PHP programs, and I had some bumps and tumbles along the way, but in the end I passed five levels and defeated six generals, and all the functions that should be implemented were realized. The following two functions are a set that I have used during the development process. This set of functions mainly implements the splitting of strings and the combination of strings. Programmers are accustomed to looking at examples. Let's look at a set of examples.

Split character string function explode()

The format of the value of $row['logistics'] is similar to: 1,2,3,4,5,6,7,8

Php code

$logistics=explode(",", $row['logistics']);  
$count  =  count($logistics);  
for($i=0;$i<$count;$i++){  
    echo $logistics[$i];  
}

So what I print out is 1 2 3 4 5 6 7 8.

Splicing string function implode()

Php code

<?php  
$arr = array(&#39;Hello&#39;,&#39;World!&#39;);  
echo implode(" ",$arr);  
?>

Output: Hello World!

Okay, now it’s up to you what you want to use this data for. .


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Factory Method PatternNext article:Factory Method Pattern