Home > Backend Development > PHP Tutorial > php 关联数组?枚举数组?

php 关联数组?枚举数组?

WBOY
Release: 2016-06-06 20:10:25
Original
1926 people have browsed it

请解释一下请解释一下请解释一下请解释一下

回复内容:

请解释一下请解释一下请解释一下请解释一下

<code>struct {
union {
long lval;
double dval;
struct {
char *val;
int len;
} str;
HashTable *ht;
zend_object_value obj;
} value;
zend_uint refcount;
zend_uchar type;
zend_uchar is_ref;
} zval;

 
PHP_FUNCTION(explain)
{
zval *uservar;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", uservar) == FAILURE) {
RETURN_NULL();
}

switch (Z_TYPE_P(uservar)) {
case IS_NULL:
php_printf("NULL ");
break;
case IS_BOOL:
php_printf("Boolean: %s ", Z_LVAL_P(uservar) ? "TRUE" : "FALSE");
break;
case IS_LONG:
php_printf("Long: %ld ", Z_LVAL_P(uservar));
break;
case IS_DOUBLE:
php_printf("Double: %f ", Z_DVAL_P(uservar));
break;
case IS_STRING:
php_printf("String: ");
PHPWRITE(Z_STRVAL_P(uservar), Z_STRLEN_P(uservar));
php_printf(" ");
break;
case IS_RESOURCE:
php_printf("Resource ");
break;
case IS_ARRAY:
php_printf("Array ");
break;
case IS_OBJECT:
php_printf("Object ");
break;
default:
php_printf("Unknown ");
}

RETURN_TRUE;
} 
</code>
Copy after login

php没有数组,实际上是用的Hashtable,数组的叫法是误传,就象世上本没有路,走的人多了,就把走过的地方叫路

我只知道PHP里面的:

  • 索引数组[1,2,3,6,6,90]

  • 关联数组['a' => 1, 'b' => 9, 'f' => ko]

PHP中的枚举数组也就是指的关联数组,关联数组的下标也就是key值可以是无序的,一般是字符串类型;比如:
array('one'=>'1','three'=>'2', 'fore'=>'3');

索引数组的下标(key)是有序的,一般为int型,比如:
array('one', 'two', 'three')
这个数组默认的下标就是0,1,2;(另外:索引数组的下标默认从0开始)

Related labels:
php
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