将多个数组合并起来
1.合并数组
array_merge()函数将数组合并到一起,返回一个联合的数组,所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加,其形式为:
- array array_merge (array array1 array2…,arrayn)
将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面,返回作为结果的数组。
如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值,然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。
如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引,实例如下:
- $face = array("j","q","k","a");
- $numbered = array("2","3","4","5","6","7","8","9");
- $cards = array_merge($face, $numbered);
- shuffle($cards);
- print_r($cards);
这将返回如下所示的结果:
- array ( [0] => a [1] => 4 [2] => 9 [3] => 3 [4] => k [5] => 7 [6] => 5 [7] => q [8] => 6 [9] => 8 [10] => 2 [11] => j )
2.递归追加数组
array_merge_recursive()函数与array_merge()相同,可以将两个或多个数组合并在一起,形成一个联合的数组,两者之间的区别在于,当某个输入数组中的某个键己经存在于结果数组中时该函数会采取不同的处理方式,array_merge()会覆盖前面存在的键/值对,替换为当前输入数组中的键/值对,而array_merge_recursive()将把两个值合并在一起,形成一个新的数组,并以原有的键作为数组名。还有一个数组合并的形式,就是递归追加数组,其形式为:
- array array_merge_recursive( array key,array values )
实例如下:
- $class1 = array("john" => 100, "james" => 85);
- $class2 = array("micky" => 78, "john" => 45);
- $classscores = array_merge_recursive($class1, $class2);
- print_r($classscores);
这将返回如下结果:
- array ( [john] => array ( [0] => 100 [1] => 45 ) [james] => 85 [micky] => 78 )
3.连接两个数组
array_combine()函数会得到一个新数组,它由一组提交的键和对应的值组成,其形式为:
- array array_merge(array array1,array array2[…,array arrayn])
注意,两个输入数组必须大小相同,不能为空,实例如下:
- $abbreviations = array("al","ak","az","ar");
- $states = array("alabama","alaska","arizona","arkansas");
- $statemap = array_combine($abbreviations,$states);
- print_r($statemap);
这会返回:
- array ( [al] => alabama [ak] => alaska [az] => arizona [ar] => arkansas )
波比源码 » php中数组合并操作
levaquin 250mg price levaquin pills
brand avodart order celebrex generic purchase ondansetron generic
order spironolactone 25mg order diflucan without prescription diflucan 200mg price
fildena 100mg pills order nolvadex 10mg generic buy robaxin without prescription
buy sildenafil 100mg generic sildenafil for men estradiol 1mg us
order lamictal 50mg pills lamictal price tretinoin gel over the counter
tadalafil 10mg tablet purchase voltaren online cheap order diclofenac sale
order indomethacin 50mg purchase suprax amoxicillin 250mg pills
levitra vs cialis best way to take cialis buy viagra without prescription
anastrozole online order anastrozole generic purchase sildenafil pills
tadalafil 20mg en ligne sildenafil generique sildenafil 100mg sans ordonnance en france
oral prednisone buy generic prednisone 40mg order viagra pill
order accutane 10mg sale amoxicillin 1000mg uk buy ivermectin 6mg
catapres price order spiriva 9mcg oral spiriva 9 mcg
purchase alendronate generic alendronate 35mg without prescription buy generic pepcid
buy benicar 10mg online generic olmesartan 10mg order acetazolamide 250 mg without prescription
imdur 20mg pill imuran 50mg us order telmisartan generic
order bupropion generic order strattera 25mg pill seroquel 50mg price
order molnunat 200 mg generic buy lansoprazole online buy lansoprazole 30mg sale
buy sertraline 50mg generic kamagra 100mg for sale order sildenafil online cheap
cialis overnight shipping Generic cialis next day delivery order generic sildenafil 50mg
order generic naltrexone order naltrexone 50mg without prescription abilify online order
order avlosulfon for sale order generic allegra 180mg aceon 4mg drug
buy medroxyprogesterone generic medroxyprogesterone 5mg canada order periactin 4mg online
buy fluvoxamine for sale luvox 50mg pill generic glucotrol
azithromycin 500mg pill zithromax for sale online neurontin canada
furosemide 100mg over the counter hydroxychloroquine 200mg generic purchase hydroxychloroquine online cheap
itraconazole pills tinidazole 500mg canada order tinidazole 500mg sale
norvasc tablet viagra 25mg for sale purchase tadalafil pill
clozapine 50mg usa buy combivent pills purchase decadron pill
sildenafil 100mg oral order lisinopril 5mg generic purchase lisinopril pills
buy prilosec sale buy prilosec pill real money spins
zyvox 600 mg us buy linezolid 600mg sale online casino for real cash
buy generic metoprolol 50mg tenormin price levitra 10mg cheap
help writing papers research paper help online online poker free
writing dissertation service best essay writing websites generic viagra
order triamcinolone 4mg online triamcinolone over the counter desloratadine 5mg usa
priligy pills dapoxetine order buy synthroid 150mcg generic
brand cialis 10mg tadalafil 40mg oral viagra over the counter
orlistat 60mg brand order zovirax pill zovirax without prescription
allopurinol canada buy rosuvastatin 10mg generic brand ezetimibe 10mg
sumatriptan tablet dutasteride over the counter avodart 0.5mg over the counter
order tamsulosin 0.4mg spironolactone generic spironolactone online order
cost cialis 40mg order generic tadalafil order cipro 1000mg generic
buy simvastatin generic cheap simvastatin 20mg propecia 5mg generic
metronidazole 200mg usa metronidazole 200mg pills order bactrim online
cheap cialis buy cialis 40mg viagra pills 150mg
viagra 50mg drug cheap viagra generic cialis super active
buy ceftin cefuroxime 250mg without prescription purchase methocarbamol online cheap
trazodone 50mg pill order suhagra 100mg for sale sildenafil 100mg brand
blackjack for money real money casino online tadalafil generic
buy furosemide 40mg lasix tablet hydroxychloroquine 200mg brand
order prednisone for sale order prazosin 2mg pill mebendazole price