array_keys_PHP array_keys()函数与示例

array_keys

PHP array_keys()函数 (PHP array_keys() function)

array_keys() function is used to get the keys of an array, it accepts an array as an argument and returns a new array containing keys.

array_keys()函数用于获取数组的键,它接受一个数组作为参数并返回一个包含键的新数组。

Syntax:

句法:

    array_keys(input_array, [value], [strict]);

Here,

这里,

  • input_array is an array (i.e. input array).

    input_array是一个数组(即输入数组)。

  • value is an optional parameter, it is used to define a value if the value is defined, then the only keys having that value are returned.

    value是一个可选参数,如果定义了值,则用于定义值,然后仅返回具有该值的键。

  • strict is also an optional parameter, it is default set to false if we set it true the type of values will be checked.

    严格也是一个可选的参数,它是默认设置为false,如果我们把它真值的类型将被检查。

Examples:

例子:

    Input:
$per = array("name" => "Amit", "age" => 21, "gender" => "Male");
Output:
Array       
(
[0] => name    
[1] => age     
[2] => gender  
)

PHP code 1: array with and without containing keys

PHP代码1:包含和不包含键的数组

<?php
$per = array("name" => "Amit", "age" => 21, "gender" => "Male");
print ("keys array...\n");
print_r (array_keys($per));
//array with out keys 
$arr = array("Hello", "world", 100, 200, -10);
print ("keys array...\n");
print_r (array_keys($arr));    
?>

Output

输出量

keys array...      
Array       
(
[0] => name    
[1] => age     
[2] => gender  
)
keys array...      
Array       
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
) 

PHP code 2: Using value and strict mode

PHP代码2:使用值和严格模式

<?php
$arr = array("101" => 100, "102" => "100", "103" => 200);
print("output (default function call)...\n");
print_r (array_keys($arr));    
print("output (with checking value)...\n");
print_r (array_keys($arr, 100));        
print("output (with checking value & strict mode)...\n");
print_r (array_keys($arr, 100, true));            
?>

Output

输出量

output (default function call)...
Array         
(             
[0] => 101
[1] => 102
[2] => 103
)             
output (with checking value)...  
Array         
(             
[0] => 101
[1] => 102
)             
output (with checking value & strict mode)...
Array         
(             
[0] => 101
)  

翻译自: https://www.includehelp.com/php/array_keys-function-with-example.aspx

array_keys

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544236.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

再见Postman,这款API神器更好用!

代码未动&#xff0c;文档先行其实大家都知道 API 文档先行的重要性&#xff0c;但是在实践过程中往往会遇到很多困难。程序员最讨厌的两件事&#xff1a;1. 写文档&#xff0c;2. 别人不写文档。大多数开发人员不愿意写 API 文档的原因是写文档短期收益远低于付出的成本&#…

strtolower_PHP strtolower()函数与示例

strtolowerPHP strtolower()函数 (PHP strtolower() function) strtolower() function is a string function, it accepts the string and returns an lowercase string. strtolower()函数是一个字符串函数&#xff0c;它接受该字符串并返回小写字符串。 Syntax: 句法&#xf…

如何保证数据库和缓存双写一致性?

前言数据库和缓存&#xff08;比如&#xff1a;redis&#xff09;双写数据一致性问题&#xff0c;是一个跟开发语言无关的公共问题。尤其在高并发的场景下&#xff0c;这个问题变得更加严重。我很负责的告诉大家&#xff0c;该问题无论在面试&#xff0c;还是工作中遇到的概率非…

面试官:AtomicInteger是如何保证线程安全?

blog.csdn.net/nanhuaibeian/article/details/120936139一、为什么引入 AtomicInteger &#xff1f;谈到线程安全&#xff0c;会首先想到了synchronized 和 Lock,但是这种方式又有一个名字&#xff0c;叫做互斥锁&#xff0c;一次只能有一个持有锁的线程进入&#xff0c;再加上…

机器学习 训练验证测试_测试前验证| 机器学习

机器学习 训练验证测试In my previous article, we have discussed about the need to train and test our model and we wrote a code to split the given data into training and test sets. 在上一篇文章中&#xff0c;我们讨论了训练和测试模型的必要性&#xff0c;并编写了…

如何判断线程池已经执行完所有任务了?

作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;很多场景下&#xff0c;我们需要等待线程池的所有任务都执行完&#xff0c;然后再进行下一步操作。对于线程 Thread …

IRCTC的完整形式是什么?

IRCTC&#xff1a;印度铁路餐饮和旅游公司 (IRCTC: Indian Railways Catering and Tourism Corporation) IRCTC is an abbreviation of Indian Railways Catering and Tourism Corporation. It is a subsidiary of the Indian Railway established by the Ministry of Railways…

分布式锁的 3 种实现方案!

前言 大家好&#xff0c;我是磊哥。今天跟大家探讨一下分布式锁的设计与实现。希望对大家有帮助&#xff0c;如果有不正确的地方&#xff0c;欢迎指出&#xff0c;一起学习&#xff0c;一起进步哈~分布式锁概述数据库分布式锁Redis分布式锁Zookeeper分布式锁三种分布式锁对比1.…

java学习笔记16--异常

java学习笔记16--异常 异常 异常时导致程序中断运行的一种指令流&#xff0c;如果不对异常进行正确的处理&#xff0c;则可能导致程序的中断执行&#xff0c;造成不必要的损失&#xff0c; 所以在程序的设计中必须要考虑各种异常的发生&#xff0c;并正确的做好相应的处理&am…

ruby hash添加数据_如何在Ruby中向Hash添加元素?

ruby hash添加数据Before going through the ways to add elements to the hash instances, let us understand what could be called as a hash element. So, Hash is the collection of keys and their values. For example, 在介绍向哈希实例添加元素的方法之前&#xff0c;…

线程安全问题的 3 种解决方案!

作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;线程安全是指某个方法或某段代码&#xff0c;在多线程中能够正确的执行&#xff0c;不会出现数据不一致或数据污染的…

黑色30s高并发IIS设置

在这篇博文中&#xff0c;我们抛开对阿里云的怀疑&#xff0c;完全从ASP.NET的角度进行分析&#xff0c;看能不能找到针对问题现象的更合理的解释。 “黑色30秒”问题现象的主要特征是&#xff1a;排队的请求&#xff08;Requests Queued&#xff09;突增&#xff0c;到达HTTP.…

我们可以覆盖Java中的main()方法吗?

The question is that "Can we override main() method in Java?" 问题是“我们可以覆盖Java中的main()方法吗&#xff1f;” No, we cant override the main() method in java. 不&#xff0c;我们不能覆盖java中的main()方法 。 First, we will understand what …

一文读懂MySQL查询语句的执行过程

需要从数据库检索某些符合要求的数据&#xff0c;我们很容易写出 Select A B C FROM T WHERE ID XX 这样的SQL&#xff0c;那么当我们向数据库发送这样一个请求时&#xff0c;数据库到底做了什么&#xff1f;我们今天以MYSQL为例&#xff0c;揭示一下MySQL数据库的查询过程&a…

angularJS的$http.post请求,.net后台接收不到参数值的解决方案

JS通用部分var shoppingCartModule angular.module(starter, [ionic], function ($httpProvider) {// Use x-www-form-urlencoded Content-Type$httpProvider.defaults.headers.post[Content-Type] application/x-www-form-urlencoded;charsetutf-8;/*** The workhorse; conve…

带有示例的Python列表reverse()方法

列出reverse()方法 (List reverse() Method) reverse() method is used to reverse the elements of the list, the method is called with this list (list in which we have to reverse the elements) and it reverses all elements in the list. reverse()方法用于反转列表中…

复杂度O(n)倒转链表

1 public class ListNode {2 int val;3 ListNode next;4 ListNode(int x) { val x; }5 ListNode(){}6 7 public static ListNode revese(ListNode input)8 {9 ListNode head new ListNode();//头插法的头 10 ListNode cur in…

synchronized底层是如何实现的?

作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;想了解 synchronized 是如何运行的&#xff1f;就要先搞清楚 synchronized 是如何实现&#xff1f;synchronized 同步…

java sublist_Java Vector subList()方法与示例

java sublist向量类subList()方法 (Vector Class subList() method) subList() method is available in java.util package. subList()方法在java.util包中可用。 subList() method is used to return a set of sublist [it returns all those elements exists in a given rang…

单例模式 4 种经典实现方法

0.前言 如果你去问一个写过几年代码的程序员用过哪些设计模式&#xff0c;我打赌&#xff0c;90%以上的回答里面会带【单例模式】。甚至有的面试官会直接问&#xff1a;说一下你用过哪些设计模式&#xff0c;单例就不用说了。你看&#xff0c;连面试官都听烦了&#xff0c;火爆…