Home >Backend Development >PHP Tutorial >Analysis of related methods of converting PHP array to string and converting PHP string to array_PHP tutorial

Analysis of related methods of converting PHP array to string and converting PHP string to array_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:29:311117browse

We introduce to you todayPHP array to string implode()

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>$vegetables[0] = "corn";  </SPAN><LI class=alt><SPAN>$vegetables[1] = "broccoli";  </SPAN><LI class=""><SPAN>$vegetables[2] = "zucchini";  </SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>text</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>implode</FONT></SPAN><SPAN>(",", $vegetables);  </SPAN></SPAN><LI class=""><SPAN>echo $text;  </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span><span></span>
</li></ol>

Running results

corn , broccoli, zucchini

2 PHP string to array explode()

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>text</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"corn, broccoli, zucchini"</FONT></SPAN><SPAN>;  </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>vegetables</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>explode</FONT></SPAN><SPAN>(", ", $text);  </SPAN></SPAN><LI class=""><SPAN>print_r($vegetables);  </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span>
</li></ol>

Running result:

<ol class="dp-xml">
<li class="alt"><span><span>Array  </span></span></li>
<li class=""><span>(  </span></li>
<li class="alt">
<span>[0] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> corn  </span>
</li>
<li class="">
<span>[1] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> broccoli  </span>
</li>
<li class="alt">
<span>[2] =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> zucchini  </span>
</li>
<li class=""><span>) </span></li>
</ol>

The above two pieces of code are the relevant codes that we introduce to you about converting PHP arrays to strings and PHP strings to arrays.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446366.htmlTechArticleThe PHP array to string implode() we introduce to you today? php $vegetables[0]="corn "; $vegetables[1]="broccoli"; $vegetables[2]="zucchini"; $ text = implode (",",$vegetables)...
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