1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php 压入元素 php 数组增加元素的方法 array_push 和 array_merge

php 压入元素 php 数组增加元素的方法 array_push 和 array_merge

时间:2022-06-25 09:40:30

相关推荐

php  压入元素 php 数组增加元素的方法 array_push 和 array_merge

本文的起因是今天需要给一个数组添加成员,一个是无序数组,直接往里扔就可以,另一个是key-value形式的数组。

无序数组只要array_push即可,key-value数组如果数量少,也可以用 $data['pussy'] = 'wagon'形式。

array_push(array,value1,value2…)

参数描述

array必需。规定数组。

value1必需。规定要添加的值。

value2可选。规定要添加的值。

例子:

$config = require_once __DIR__ . '/../vendor/xxx.php';

array_push($config['providers'],

xxx\Providers\HttpClientServiceProvider::class,

xxx\Providers\SmsServiceProvider::class,

xxx\Providers\QrCodeServiceProvider::class,

\Intervention\Image\ImageServiceProvider::class,

xxx\Providers\ImageServiceProvider::class,

xxx\Providers\WordSegmentServiceProvider::class,

xxx\Providers\WechatServiceProvider::class,

xxx\Providers\RecommendServiceProvider::class,

Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider::class

);

array_merge(array1,array2,array3…)

参数描述

array1必需。规定数组。

array2可选。规定数组。

array3可选。规定数组。

例子接上:

$config['aliases'] = array_merge($config['aliases'], [

'HttpClient' => xxx\Facades\HttpClient::class,

'Sms' => xxx\Facades\Sms::class,

'QrCode' => xxx\Facades\QrCode::class,

'Image' => \Intervention\Image\Facades\Image::class,

'ImageUpload' => xxx\Facades\Image::class,

'WordSegment' => xxx\Facades\WordSegment::class,

'Recommend' => xxx\Facades\Recommend::class,

'Wechat' => xxx\Facades\Wechat::class,

'Omnipay' => Ignited\LaravelOmnipay\Facades\OmnipayFacade::class

]

);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。