Wolfzmus Wolfzmus - 27 days ago 8
PHP Question

Call array ['items'] not working

I have problem with my array, when i try var dump my aray is show like this

Example :

var_dump($mastervendor->listvendor());


result is :
array(3) { ["items"]=> object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> NULL ["num_rows"]=> int(6358) ["type"]=> int(0) } ["count"]=> int(6358) ["exist"]=> bool(true) }


But when i try call
var_dump($mastervendor->listvendor()['items']);


it said
Failed to load resource: the server responded with a status of 500 (Internal Server Error)


Why i cant call
['items']
??? Did i do something worng??

my php is
PHP Version 5.3.10-1ubuntu3.4

Answer Source

my php is PHP Version 5.3.10-1ubuntu3.4

Since PHP 5.4 it's possible:

Source : https://secure.php.net/manual/en/language.types.array.php#example-62

till then

$some_variable = $mastervendor->listvendor();
print_r($some_variable['items']);

On PHP 5.3 or earlier, you have to use a temporary variable.