属性阵列 [英] properties as array

查看:112
本文介绍了属性阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做这样的事情,而无需使用额外的变量:

  className类{
  公共静态函数func(){
    返回阵列(真,将val2');
  }
}如果(类名:: FUNC()[0]){
  回声'doğru';
}其他{
  呼应'Yanlış';
}


解决方案

类名:: FUNC()[0] 被称为数组语法的,而不是在所有的PHP版本有效的语法。它<击>为可在PHP 5.4开始,<击>目前处于测试阶段发布2012年3月对于早期PHP版本,你需要使用一个额外的变量在某处存储阵列从返回的className :: FUNC()

查看实施细节PHP 5.4阵列文档

I want to do something like this without using extra variables:

class className {
  public static function func(){
    return array('true','val2');
  }
}

if(className::func()[0]) {
  echo 'doğru';
} else {
  echo 'Yanlış';
}

解决方案

className::func()[0] is called array dereferencing, and is not valid syntax in all PHP versions. It will be is available starting in PHP 5.4, currently in beta, released March 2012. For earlier PHP version, you will need to use an extra variable somewhere to store the array returned from className::func().

See the PHP 5.4 Array documentation for implementation details.

这篇关于属性阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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