PHP array_pad()函数与示例

PHP array_pad()函数 (PHP array_pad() function)

array_pad() function is used to pad an array to given size with a specified value and returns a new array with a specified value.

array_pad()函数用于将数组填充到具有指定值的给定大小,并返回具有指定值的新数组。

Syntax:

句法:

    array_pad(array, size, value);

Here,

这里,

  • array is an array in which we have to add the elements.

    数组是我们必须在其中添加元素的数组。

  • size is the length/size of the array.

    size是数组的长度/大小。

  • value is the value to be added to pad an array.

    value是要填充数组的值。

Examples:

例子:

    Input:
$arr = array(10, 20, 30);
Function call:
array_pad($arr, 5, 100);
Output:
Array
(    
[0] => 10   
[1] => 20   
[2] => 30   
[3] => 100  
[4] => 100  
)

PHP code:

PHP代码:

<?php
$arr = array(10, 20, 30);
//padding to 5 elements with value 100
$result = array_pad($arr, 5, 100);
//printing
print_r ($result);
$arr = array("Hello", "Guys");
//padding to 5 elements with value "Bye!"
$result = array_pad($arr, 5, "Bye!");
//printing
print_r ($result);    
?>

Output

输出量

Array
(    
[0] => 10   
[1] => 20   
[2] => 30   
[3] => 100  
[4] => 100  
)    
Array
(    
[0] => Hello
[1] => Guys 
[2] => Bye! 
[3] => Bye! 
[4] => Bye! 
)

翻译自: https://www.includehelp.com/php/array_pad-function-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544173.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring Boot 优雅配置多数据源

大约在19年的这个时候&#xff0c;老同事公司在做医疗系统&#xff0c;需要和HIS系统对接一些信息&#xff0c;比如患者、医护、医嘱、科室等信息。但是起初并不知道如何与HIS无缝对接&#xff0c;于是向我取经。最终经过讨论采用了视图对接的方式&#xff0c;大致就是HIS系统提…

(转)新ITC提交APP常见问题与解决方法(Icon Alpha,Build version,AppIcon120x120)(2014-11-17)...

1&#xff09;ICON无法上传&#xff0c;提示图片透明&#xff08;有Alpha通道&#xff09;苹果现在不接受png里的Alpha了&#xff0c;提交的图标带有Alpha通道就提示&#xff1a;简单处理&#xff1a;用自带的预览打开&#xff0c;导出时不勾选Alpha&#xff0c;仍保存为png格式…

python 向量取整数_随机整数向量| 使用Python的线性代数

python 向量取整数Prerequisite: 先决条件&#xff1a; Defining a Vector using list 使用列表定义向量 Defining Vector using Numpy 使用Numpy定义向量 Random Integer Vector is a type of vector having a random integer value at each entry. Such types of vectors ha…

Spring 夺命 35 问!

有人说&#xff0c;“Java程序员都是Spring程序员”&#xff0c;可以看出Spring在Java世界里举足轻重的作用。基础1.Spring是什么&#xff1f;特性&#xff1f;有哪些模块&#xff1f;Spring Logo一句话概括&#xff1a;Spring 是一个轻量级、非入侵式的控制反转 (IoC) 和面向切…

Android百度地图开发03之地图控制 + 定位

前两篇关于百度地图的blog写的是&#xff0c;一些基本图层的展示 和 覆盖物的添加地理编码和反地理编码。 接下来&#xff0c;这篇blog主要说一些关于地图控制方面的内容和定位功能。 百度地图提供的关于地图的操作主要有&#xff1a;单击、双击、长按、缩放、旋转、俯视等。 地…

软件工程需要学什么_为什么我们需要软件工程?

软件工程需要学什么Software engineering is the application of the set of pre-defined procedures while developing any project. But why do we need Software engineering? What factors made us implement these predefined set of procedures and protocols while dev…

IDEA 版 Postman 面世了,功能真心强大!

IDEA是最常用的开发工具&#xff0c;很多程序员都想把它打造成一站式开发平台&#xff0c;于是安装了各种各样的插件。最近发现了一款IDEA插件RestfulFastRequest&#xff0c;细节做的真心不错&#xff0c;说它是IDEA版的Postman也不为过&#xff0c;推荐给大家&#xff01;Res…

DNS子域授权

转载于:https://blog.51cto.com/changeflyhigh/1697257

mongo数据库插入数据_深入研究Mongo数据库

mongo数据库插入数据More popularly known as "mongoDB". It is a no-sql based database. 俗称“ mongoDB” 。 这是一个基于无SQL的数据库。 BASIC STRUCTURE OF MONGO DB MONGO DB的基本结构 A COLLECTION IN MONGODB having 3 DOCUMENTS MONGODB中有3个文档的集…

java方法重载和重载方法_我们可以在Java中重载main()方法吗?

java方法重载和重载方法The question is that "can we overload main() method in Java?" 问题是“我们可以在Java中重载main()方法吗&#xff1f;” Yes, We can overload the main() method in Java. 是的&#xff0c;我们可以重载Java中的main()方法 。 JVM cal…

五分钟,手撸一个Spring容器!

Spring是我们最常用的开源框架&#xff0c;经过多年发展&#xff0c;Spring已经发展成枝繁叶茂的大树&#xff0c;让我们难以窥其全貌。这节&#xff0c;我们回归Spring的本质&#xff0c;五分钟手撸一个Spring容器&#xff0c;揭开Spring神秘的面纱&#xff01;从什么是IOC开始…

一步一步搭建客服系统 (7) 多人共享的电子白板、画板

多人共享、同时操作的电子白板&#xff0c;让不同的参入者以不同的颜色来画画&#xff1b;可以保存当前room的内容&#xff0c;以让后来者可以直接加载所有内容。 在github上找到一个用html5 canvas实现的一个电子白板的例子&#xff1a; https://github.com/kblcuk/canvas-whi…

Spring Cloud OpenFeign 的 5 个优化小技巧!

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;OpenFeign 是 Spring 官方推出的一种声明式服务调用和负载均衡组件。它的出现就是为了替代已经进入停更维护状态的 Feign&am…

java的equals方法_Java Vector equals()方法与示例

java的equals方法向量类的equals()方法 (Vector Class equals() method) equals() method is available in java.util package. equals()方法在java.util包中可用。 equals() method is used to check whether this Vector is the same or equals to the given object (ob) or …

推荐几个好文章

1 cocos2dx各种行动 http://www.cnblogs.com/linux-ios/archive/2013/04/06/3001946.html 2 cocos2dx自己定义曲线 http://blog.csdn.net/ufolr/article/details/7447773 3 lua中载入cocostudio动画&#xff0c;触发帧事件&#xff08;非常全&#xff0c;非常具体。还有源代码…

treeset java_Java TreeSet first()方法与示例

treeset javaTreeSet类的first()方法 (TreeSet Class first() method) first() method is available in java.util package. first()方法在java.util包中可用。 first() method is used to retrieve the first lowest element in this TreeSet. first()方法用于检索此TreeSet中…

Java常用类:7000字一次性帮你总结好啦!

来源&#xff1a;cnblogs.com/lwtyyds/p/15678152.html常用类概述内部类内部类的分类&#xff1a;1.成员内部类&#xff08;非静态内部类&#xff09;2.局部内部类4.匿名内部类Object类Object类常用方法&#xff1a;1.equals方法2.hashCode方法3.toString方法4.finzlize方法包装…

CentOS6.4系统启动失败故障排查

转&#xff1a;http://www.centoscn.com/CentosBug/osbug/2014/1028/4011.html 操作系统启动失败如下图报错&#xff1a; 故障现象&#xff1a; 从图中可以看到&#xff0c;操作系统启动的过程中&#xff0c;fsck在执行文件系统检测时出现了错误&#xff0c;并且是在检查/dev/m…

hashmap clone_Java HashMap clone()方法与示例

hashmap cloneHashMap类clone()方法 (HashMap Class clone() method) clone() method is available in java.util package. clone()方法在java.util包中可用。 clone() method is used to get a cloned copy of this HashMap instance or in other words, we can say it return…

Linux内存管理--物理内存分配【转】

转自&#xff1a;http://blog.csdn.net/myarrow/article/details/8682819 1. First Fit分配器 First Fit分配器是最基本的内存分配器&#xff0c;它使用bitmap而不是空闲块列表来表示内存。在bitmap中&#xff0c;如果page对应位为1&#xff0c;则表示此page已经被分配&#xf…