1

My function getStockStatus($stock_Id) returns

array(3) { ["pqty"]=> string(2) "10" ["sqty"]=> int(20) ["cqty"]=> int(-10) }

(as var_dump).

If I use getStockStatus(12)['pqty'] I get an error Parse error: syntax error, unexpected '[', expecting ',' or ';' in D:\xampp\htdocs\acs\ac_stockstatus.php on line 50.

How to use this function?

Priyamanu
  • 183
  • 1
  • 3
  • 11

3 Answers3

2

That kind of syntax was introduced in PHP 5.4. If you're using 5.3 or below, you need 2 steps:

$stockStatus = getStockStatus(12);
$pqty = $stockStatus['pqty'];
1

Seems you are running on older version of PHP 5.3, this thing is handled PHP 5.4 or newer, see Mannual

You need to store this in a variable to access.

$returnVal = getStockStatus(12);
echo $returnVal['pqty'];
kamal pal
  • 4,187
  • 5
  • 25
  • 40
0

You can try array_values()php function if you want only values from this array you have.

satish
  • 11
  • 4