PHP(数组)

WBOY
Release: 2016-06-23 14:35:57
Original
1155 people have browsed it

   PHP数组不适用键访问下标默认是数字。

   1.数组头插入数据 array_unshift($array, $var);

   2.数组尾插入数据 array_push($array, $var);

   3.数组头删除数据 array_shift($array, $var);

   4.数组尾删除数据 array_pop($array, $var);

   5.判断数组中存在某值 in_array($needle, $haystack);

   6.判断数组中存在某键 array_key_exists($key, $search);

   7.获取数组键集合 array_keys($input);

   8.获取数组值集合 array_values($input);

   9.遍历数组键
        $citys=array("beijing"=>"北京","shanghai"=>"上海","guangzhou"=>"广州","shenzhen"=>"深圳","suzhou"=>"苏州",hangsha"=>"长沙");
        while($key= key($citys))
        {
          printf("%s
",$key);
          next($citys);
        }

      (如果数组没有设键或是没有全部设键,是不会输出的。)

  10.遍历数组值
       $citys=array("beijing"=>"北京","shanghai"=>"上海","guangzhou"=>"广州","shenzhen"=>"深圳","suzhou"=>"苏州","changsha"=>"长沙");
        while($value= current($citys))
        {
          printf("%s
",$value);
          next($citys);
        }

   11.数组值出现的频率统计
      array_count_values($input);

   12.移动数组指针
      next($input);//移到下一个
      prev($input);//移到前一个
      reset($input);//回到开始位置
      end($input);//移到最后位置

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template