PHP join() º¯Êý
°ÑÊý×éÔªËØ×éºÏΪһ¸ö×Ö·û´®£º
<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo join(" ",$arr);
?>
|
¶¨ÒåºÍÓ÷¨
¡¡¡¡join() º¯Êý·µ»ØÓÉÊý×éÔªËØ×éºÏ³ÉµÄ×Ö·û´®¡£
¡¡¡¡join() º¯ÊýÊÇ implode() º¯ÊýµÄ±ðÃû¡£
¡¡¡¡×¢ÊÍ£ºjoin() º¯Êý½ÓÊÜÁ½ÖÖ²ÎÊý˳Ðò¡£µ«ÊÇÓÉÓÚÀúÊ·ÔÒò£¬explode() ÊDz»Ðеģ¬Äú±ØÐë±£Ö¤ separator ²ÎÊýÔÚ string ²ÎÊý֮ǰ²ÅÐС£
¡¡¡¡×¢ÊÍ£ºjoin() º¯ÊýµÄ separator ²ÎÊýÊÇ¿ÉÑ¡µÄ¡£µ«ÊÇΪÁËÏòºó¼æÈÝ£¬ÍƼöÄúʹÓÃʹÓÃÁ½¸ö²ÎÊý¡£
Óï·¨
join(separator,array)
²ÎÊý |
ÃèÊö |
separator |
¿ÉÑ¡¡£¹æ¶¨Êý×éÔªËØÖ®¼ä·ÅÖõÄÄÚÈÝ¡£Ä¬ÈÏÊÇ ""£¨¿Õ×Ö·û´®£©¡£ |
array |
±ØÐè¡£Òª×éºÏΪ×Ö·û´®µÄÊý×é¡£ |
¼¼Êõϸ½Ú
·µ»ØÖµ£º |
·µ»ØÓÉÊý×éÔªËØ×éºÏ³ÉµÄ×Ö·û´®¡£ |
PHP °æ±¾£º |
4+ |
¸üÐÂÈÕÖ¾£º |
ÔÚ PHP 4.3.0 ÖУ¬separator ²ÎÊý±ä³É¿ÉÑ¡µÄ¡£ |
¸ü¶àʵÀý
Óò»Í¬µÄ×Ö·û·Ö¸ôÊý×éÔªËØ£º
<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo join(" ",$arr)."<br>";
echo join("+",$arr)."<br>";
echo join("-",$arr)."<br>";
echo join("X",$arr);
?>
|
(ÔðÈα༣ºadmin) |