相思资源网 Design By www.200059.com

概述
要访问一个变量的内容,可以直接使用其名称。如果该变量是一个数组,可以使用变量名称和关键字或索引的组合来访问其内容。
像其他变量一样,使用运算符=可以改变数组元素的内容。数组单元可以通过 array[key] 语法来访问。

PHP中常用的数组操作方法笔记整理

数组的基本操作
php定义数组:

<"key"] = "values"; 
"htmlcode">
<"htmlcode">
<"foo" => "bar",
    "bar" => "foo",
  ];

  print_r($array);//Array ( [foo] => bar [bar] => foo ) 

"htmlcode">
<"htmlcode">
<"htmlcode">
<"htmlcode">
<"htmlcode">
<"htmlcode">
 <"htmlcode">
<"htmlcode">
<"I","Am","A","PHP","er");
  $newArray = array_combine($number,$array);
  print_r($newArray);//Array ( [1] => I [2] => Am [3] => A [4] => PHP [5] => er ) 
"htmlcode">
<"red", "green", "blue", "yellow");
  count ($color); //得到4
  array_splice($color,1,1); //删除第二个元素
  print_r(count ($color)); //3
  echo $color[2]; //yellow
  echo $color[1]; //blue
"htmlcode">
<"red", "green", "blue", "yellow","blue","green");
  $result = array_unique($color);
  print_r($result);//Array ( [0] => red [1] => green [2] => blue [3] => yellow ) 
"htmlcode">
<"red","blue","red","Black");
  print_r($array);
  echo "<br />";
  $array = array_flip($array);//
  print_r($array);//Array ( [red] => 2 [blue] => 1 [Black] => 3 ) 
"htmlcode">
<meta charset="utf-8">
<"red","blue","red","Black");
  $result=array_search("red",$array)//array_search(value,array,strict)
  if(($result === NULL)){
    echo "不存在数值red";
  }else{
    echo "存在数值 $result";//存在数值 0 
  }
?> 

标签:
PHP,数组

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“PHP中常用的数组操作方法笔记整理”

暂无PHP中常用的数组操作方法笔记整理的评论...