Rumah > pembangunan bahagian belakang > tutorial php > PHP数组转字符串与PHP字符串转数组的相关方法解析_PHP教程

PHP数组转字符串与PHP字符串转数组的相关方法解析_PHP教程

WBOY
Lepaskan: 2016-07-15 13:29:31
asal
1115 orang telah melayarinya

我们今天为大家介绍的PHP数组转字符串 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>
<li class=""><span>$vegetables[0] = "corn";  </span></li>
<li class="alt"><span>$vegetables[1] = "broccoli";  </span></li>
<li class=""><span>$vegetables[2] = "zucchini";  </span></li>
<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>
</li>
<li class=""><span>echo $text;  </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span><span></span>
</li>
</ol>
Salin selepas log masuk

运行结果

corn,broccoli,zucchini

2 PHP字符串转数组 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>
<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>
</li>
<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>
</li>
<li class=""><span>print_r($vegetables);  </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Salin selepas log masuk

运行结果:

<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>
Salin selepas log masuk

以上两段代码就是我们向大家介绍的关于PHP数组转字符串和PHP字符串转数组的相关代码。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446366.htmlTechArticle我们今天为大家介绍的 PHP数组转字符串 implode() ? php $vegetables[0]="corn"; $vegetables[1]="broccoli"; $vegetables[2]="zucchini"; $ text = implode (",",$vegetables)...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan