0

Why does this code work:

$row = $stmt->fetch();
$result = array("status"=>"0", "uid"=>($row["id"]));

And this one does not:

$result = array("status"=>"0", "uid"=>(($stmt->fetch())["id"]));
Valentin Solina
  • 309
  • 1
  • 7

1 Answers1

2

Since PHP 5.4 it's possible to do what you did.

getSomeArray()[$someKey]

Reference: http://php.net/manual/en/language.types.array.php#example-88

Prior to PHP 5.3, you'll need to use a temporary variable.

Matt Browne
  • 12,169
  • 4
  • 59
  • 75
imulsion
  • 8,820
  • 20
  • 54
  • 84