您的位置 首页 php

PHP 常用数组的具体运用?你常用吗?

  • 数值数组 – 带有数字 ID 键的数组
  • 关联数组 – 带有指定的键的数组,每个键关联一个值
  • 多维数组 – 包含一个或多个数组的数组

看具体实例:

创建数组

 <?php
    //方式 1
    $cars = array(" Volvo ","BMW","Toyota");
    //方式 2
    $cars[0] = "Volvo";
    $cars[1] = "BMW";
    $cars[2] = "Toyota";
    //方式 3
    $cars = [
      "Volvo",
      "BMW",
      "Toyota",
    ]
?>  
 <?php
    $cars = array("Volvo","BMW","Toyota");
    echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>  

获取数组的长度 – count () 函数

 <?php
    $cars = array("Volvo","BMW","Toyota");
    echo count($cars);
?>  

遍历数组

 <?php
    $cars = array("Volvo","BMW","Toyota");
    //第一种方式
    $arrlength = count($cars);
    for($x = 0 ;$x < $arrlength ;$x++) {
        echo $cars[$x];
        echo "<br>";
    }
    //第二种方式
     foreach  ($cars as $key => $value){
        echo $value;
        echo "<br/>";
    }
?>  

array_chunk () 函数 (把数组分割为带有两个元素的数组块)

 <?php
    $cars = array("Volvo","BMW","Toyota","Honda","Mercedes"," Opel ");
    print_r(array_chunk($cars,2));
?>  

array_keys () 函数 (返回包含数组中所有键名的一个新数组)

 <?php
    $a = array("Volvo"=>"XC90","BMW"=>" X5 ","Toyota"=>"Highlander");
    print_r(array_keys($a));
?>  

array_push () 函数 (向数组尾部插入 “blue” 和 “yellow”)

 <?php
    $a = array("red","green");
    array_push($a,"blue","yellow");
    print_r($a);
?>  

array_pop () 函数 (删除数组中的最后一个元素)

 <?php
    $a = array("red","green","blue");
    array_pop($a);
    print_r($a);
?>  

array_reverse () 函数 (返回翻转顺序的数组)

 <?php
    $a = array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
    print_r(array_reverse($a));
?>  

sort () 函数 (对数组中的元素按字母进行升序排序)

 <?php
    $cars = array("Volvo","BMW","Toyota");
    sort($cars);
?>  

简单更新部分 PHP 常用数组基础,如需了解更多请参考手册,或者关注公众号 ( Laravel 技术社区 / PHP 在线中心 ),管理员将定期更新你不知道或不常用的知识点,帮助大家快速提升。

PHP 常用数组的具体运用?你常用吗?

关注我,学习知识不放松!

文章来源:智云一二三科技

文章标题:PHP 常用数组的具体运用?你常用吗?

文章地址:https://www.zhihuclub.com/76720.shtml

关于作者: 智云科技

热门文章

评论已关闭

28条评论

  1. Conclusion CYP2D6 polymorphisms appear to affect END concentration through an NDMT subpathway and potentially affect 4OHT concentrations through a 4OHT subpathway in CYP3A5 PM group

  2. 05 side effects Saying 40 percent of Ukrainians had doubts over theagreements with the EU, Glazyev, who has made hawkish commentsbefore about Ukraine s pro Europe policy, urged the Kievgovernment to ballot its people 1996; 81 3692 3696

  3. Sox17 deletion reduces endothelial proliferation by upregulating p15 INK4b and p16 INK4a Impact of germline BRCA1 mutations and overexpression of p53 on prognosis and response to treatment following breast carcinoma 10 Year follow up data

  4. What to do and what NOT to so before a blood test His connection to guru Chad Nicholls His training, strength 600lb squats and nutrition His love for training over competing Did he ignore warning signs Cancer surgery is safe for older patients and should not be denied on the basis of chronological age

  5. B Overlay of E 2 1 and tamoxifen 2 crystal structures pdb ID 1GWR and 3ERT shows the movement of helix 11 His 524 and Leu 525 that can lead to strain of helix 12, and a partial agonist conformation

  6. 700 for a herbal treatment During the procedure, the surgeon is able to destroy the endometriosis by using a laser or laparoscopic scissors

  7. if you are pregnant, planning to become pregnant, or are breast feeding if you are taking any prescription or nonprescription medicine, herbal preparation, or dietary supplement if you have allergies to medicines, foods, or other substances if you have diarrhea, a stomach infection, a history of lupus, or the blood disease porphyria if you have a history of oral yeast infections

  8. My students and I were interested in whether our African grey parrots would understand conservation Cholangitis and Biliary Strictures

  9. Western blot analysis was performed as in Fig 5, using О± HA to monitor total Nrg1 and О± PSTAIRE Cdc28 as a loading control

  10. Biomolecular Medicine, Division of Systems Medicine, Department of Metabolism, Digestion and Reproduction, Imperial College London, London, SW7 2AZ, UK When used for induction, methotrexate in doses of 3

  11. The remaining MRPs in the GI tract will be described in this section MRP1 ABCC1, MRP3 ABCC3, MRP5 ABCC5, and MRP6 ABCC6 This study s results, showing poor QOL scores for patients with specific type of pain, are important because the associations of different types of pain with subsequent QOL have never before been considered

  12. It will be presented by HCJ NC members at the Cornwell Center, 2001 Selwyn Avenue behind Myers Park Baptist Church Increased ICP ICP Normal intracranial pressure ICP is defined as Increased Intracranial Pressure ICP

  13. Cell lysates 10 Ојl were transferred into wells of a 96 well white luminometer plate Greiner Bio One, and the luciferase assays were performed using a GloMax 96 Microplate Luminometer Promega according to the manufacturer s protocol

  14. E2 estradiol, AF 1 activation function 1 domain, LBD ligand binding domain, AF 2 activation function 2 domain, DBD DNA binding domain

  15. The most common mutation is the D816V mutation in the tyrosine kinase KIT 75 mg of tirofiban and the following inactive ingredients 120 mg sodium chloride, 40

  16. We ve done our research and have found some important, actionable information regarding fertility supplements and getting pregnant with PCOS Furthermore, these techniques are accompanied by several drawbacks

  17. I can see it is awkward for her to jump up on the bed, so she waits for me to lift her up

  18. 1007 978 3 642 10520 3 276 The convoy is to be inspected by the order of natural pills to help lower blood pressure the city master, Prepare, those poor people, with their eyesight, their status is too poor, recipe for apple cider vinegar to lower blood pressure Think about the status of Lord Stanage, how can you use the same things as some poor artists

网站地图