implode

(PHP 4, PHP 5, PHP 7)

implode — Join array elements with a string

implode — 将一个一维数组的值转化为字符串

Description

string implode ( string $glue , array $pieces )

string implode ( array $pieces )

//Join array elements with a glue string.

//用 glue 将一维数组的值连接为一个字符串。

Note:

implode() can, for historical reasons, accept its parameters in either order. For consistency with explode(), however, it may be less confusing to use the documented order of arguments.

因为历史原因,implode() 可以接收两种参数顺序,但是 explode() 不行。不过按文档中的顺序可以避免混淆。

Parameters

glue

Defaults to an empty string.

默认为空的字符串。

pieces

The array of strings to implode.

你想要转换的数组。

Return Values

Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

返回一个字符串,其内容为由 glue 分割开的数组的值。

Examples

/**

* Created by PhpStorm.

* User: zhangrongxiang

* Date: 2018/2/17

* Time: 下午10:52

*/

$array = array( '`lastname`', '`email`', '`phone`' );

$comma_separated = implode( ",", $array );

//`lastname`,`email`,`phone`

echo $comma_separated . PHP_EOL;

// Empty string when using an empty array:

echo '-------------------------' . PHP_EOL;

print_r( implode( 'hello', array() ) ); // string(0) ""

echo '-------------------------' . PHP_EOL;

$id_nums = array( 1, 6, 12, 18, 24 );

$id_nums = implode( ", ", $id_nums );

$sqlquery = "Select `name`,email,phone from `usertable` where user_id IN ($id_nums)";

//Select `name`,email,phone from `usertable` where user_id IN (1, 6, 12, 18, 24)

echo $sqlquery . PHP_EOL;

$sqlquery = "Select $comma_separated from `usertable` where user_id IN ($id_nums)";

//Select `lastname`,`email`,`phone` from `usertable` where user_id IN (1, 6, 12, 18, 24)

echo $sqlquery . PHP_EOL;

$ar = array( "hello", null, "world" );

echo implode( ',', $ar ) . PHP_EOL; // hello,,world

$picnames = array( "pic1.jpg", "pic2.jpg", "pic3.jpg", "pic4.jpg", "pic5.jpg", "pic6.jpg", "pic7.jpg" );

$allpics = implode( "|", array_slice( $picnames, 0, 5 ) );

//pic1.jpg|pic2.jpg|pic3.jpg|pic4.jpg|pic5.jpg

echo $allpics . PHP_EOL;

$test = implode( [ "one", 2, 3, "four", 5.67 ] );

echo $test . PHP_EOL;//one23four5.67

/

class Foo {

protected $title;

public function __construct( $title ) {

$this->title = $title;

}

public function __toString() {

return $this->title;

}

}

$array = [

new Foo( 'foo' ),

new Foo( 'bar' ),

new Foo( 'qux' )

];

//foo; bar; qux

echo implode( '; ', $array );

See

All rights reserved

php stringimplode,PHP之string之implode()函数使用相关推荐

  1. php impload 展开,PHP implode()函数用法讲解

    PHP implode() 函数 实例 把数组元素组合为一个字符串: $arr = array('Hello','World!','Beautiful','Day!'); echo implode(& ...

  2. PHP explode() 函数与implode() 函数

    1. implode() 函数 用法:把数组元素组合为字符串: <?php$arr = array('Hello','World!','I','love','BeiJing!');echo im ...

  3. implode()函数和explode()函数

    implode()函数 语法: string implode(string glue, array pieces); //将数组的内容组合成一个字符串,参数glue是字之间的分隔符号. e.g. im ...

  4. php打implode+函数,PHP implode() 函数 - PHP 基础教程

    PHP String 参考手册 把数组元素组合为一个字符串: $arr = array('Hello','World!','Beautiful','Day!'); echo implode(" ...

  5. php 刀客友朋,php explode()函数和implode()函数使用说明

    下里说道php中的explode 和implode的用法,芭蕾舞鞋,盼望对于友朋们有所辅助! 说到php,函数便长短常主要的,也是php爱好者,和喜好php进阶的朋友们必须控制的东东,学习php的友朋 ...

  6. OC与c混编实现Java的String的hashcode()函数

    首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...

  7. c++string类默认函数实现

    c++ string类默认几种函数实现. //构造函数传const指针 //参数都是取引用 /*class String { public:String(const char *str = NULL) ...

  8. string的find函数

    string的find函数找不到"\"转义字符,需要再添加一个"\\",这样就可以找到了 #include<cstdint> #include< ...

  9. C++string中find_first_not_of()函数和find_last_not_of()函数

    C++string中find_first_not_of()函数和find_last_not_of()函数 C++string中find_first_not_of()函数和find_last_not_o ...

  10. java convert函数_自己实现 java中 Convert.toDouble(String str)处理函数 | 学步园

    今天在superWaba上看到Convert.toDouble(String str),由于底层问题比较大的数就出错,现在自己写了一个 程序中info()是我加的打印,可以去掉 java中 Conve ...

最新文章

  1. java中next的用法_关于java iterator的next()方法的用法
  2. 如何让自学更有效率?
  3. 数字人民币解密:数字人民币的系统架构、产品形态是什么样的?
  4. android异步更新UI
  5. 关于协方差矩阵需要注意的一个事项
  6. Spring Boot,@ EnableWebMvc和常见用例
  7. MyBatisPlus_查询篇_入门试炼_01
  8. 计算三角形面积(信息学奥赛一本通-T1034)
  9. SpringMVC框架----RequestParam注解和RequestBody注解
  10. 异动处理中的发票类型应用(Complaint Processing)
  11. php monolog 使用,PHP 依赖工具 monolog的使用
  12. 处理uniapp开发安卓app进入打开手机的游戏加速模式
  13. 4G关键技术之MIMO
  14. 打听同事工资,我被离职了
  15. 概率 (菜鸡 dalao轻喷
  16. 无迹卡尔曼滤波估计SOC的simulink模型详解
  17. 计算机网络 通信网络笔记(自顶向下的方法)from top to the botton of MIT
  18. Mysql| order by 排序检索数据(ASC,DESC)
  19. Redis 命令 数据结构
  20. “阿里日”102 对新人举办集体婚礼,张勇证婚:“又热,又爱”!

热门文章

  1. 微信如何群发消息给所有人?
  2. 请假要组长和经理同时审批该怎么办?来看看工作流中的会签功能
  3. 回声状态网络(ESN)教程
  4. 戏精,程序员的桌面画风竟然是酱紫的!
  5. uni app修改android原生,iOS原生返回图标
  6. C语言基础之14:结构和其他数据形式
  7. python、java、ruby、node等如何提取office文档中的内容?
  8. java猜数游戏图形界面_java 猜数字游戏 swing实现带界面
  9. word中“项目符号”和后面的文字间隔太远
  10. C++搜索算法和曼哈顿距离之最少连通代价