Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

properties as array [duplicate]

Tags:

arrays

php

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ış';
}
like image 873
Lupus Avatar asked Dec 01 '22 06:12

Lupus


1 Answers

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.

like image 50
Michael Berkowski Avatar answered Dec 06 '22 02:12

Michael Berkowski