简写数组:有没有像{文字语法}或[]? [英] Shorthand for arrays: is there a literal syntax like {} or []?

查看:284
本文介绍了简写数组:有没有像{文字语法}或[]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在PHP?

我试图用(不工作):

$list = {};

这将是完美的,如果你给的关于其他速记对PHP的一些信息的链接。

It will be perfect, if you give links on some information about other shorthands for PHP.

推荐答案

更新:结果
由于PHP的5.4.0用于声明数组a 缩短语法已经出台:

$list = [];


previous答:

有不是。只有 $列表=阵列(); 但是你可以开始添加元素。

There isn't. Only $list = array(); But you can just start adding elements.

<?php
$list[] = 1;
$list['myKey'] = 2;
$list[42] = 3;

这是完全OK就PHP而言。你甚至不会得到一个 E_NOTICE未定义变量的。

E_NOTICE级错误的情况下,发出
  未初始化的工作
  变量,但不是在的情况下
  附加元素的
  未初始化数组。

E_NOTICE level error is issued in case of working with uninitialized variables, however not in the case of appending elements to the uninitialized array.

对于速记方法,有很多散落各地。如果你想找到他们刚读手动

As for shorthand methods, there are lots scattered all over. If you want to find them just read The Manual.

一些例子,只为您的娱乐:

Some examples, just for your amusement:


  1. $改编[] 速记 array_push

  2. 的foreach 结构

  3. 回声$字符串1,$字符串2,$ STRING3;

  4. 阵列串联与 +

  5. 的存在 ELSEIF

  6. 变量嵌入在字符串中, $ NAME ='杰克';回声你好$名称;

  1. $arr[] shorthand for array_push.
  2. The foreach construct
  3. echo $string1, $string2, $string3;
  4. Array concatenation with +
  5. The existence of elseif
  6. Variable embedding in strings, $name = 'Jack'; echo "Hello $name";

这篇关于简写数组:有没有像{文字语法}或[]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆