1

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

Wolfzmus
  • 463
  • 1
  • 10
  • 23
  • 1
    I don't believe you can reference an array location off a method call until like php 5.5. Try saving result to an intermediate variable. – Jeff Puckett Sep 22 '17 at 01:58
  • @JeffPuckett : Well i got that result when i try that.. I dont know if that method call in php 5.5. So how do i change intermediate variable?? – Wolfzmus Sep 22 '17 at 02:02
  • 5 going on 6 year old version of php, maybe time for an upgrade. –  Sep 22 '17 at 02:03
  • 1
    @rtfm : Well if i could change old version, cause that sevrer php not from my computer but from another computer wich i cant remote or i dont have authority to change it. – Wolfzmus Sep 22 '17 at 02:07

1 Answers1

1

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.

Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36