0

I think that I'm having a syntax issue here. I have an array that, when I dump and die it, looks like this:

^ array:1 [
    0 => array:3 [
      "something" => "-12"
      "somethingElse" => "2"
      "somethingThird" => "2"
    ]
  ]

I am having a hard time returning the actual items in the array inside this array. I've tried:

$myArray->something;
$myArray->0;
$myArray[0]->something;
$myArray[0]['something'];
$myArray['something'];

and i keep getting undefined offset errors. I think i'm not understanding the structure of this array of arrays. Can anyone help? Thank you!

EDIT: print_r of the array:

Array ( [0] => Array ( [something] => -12 [somethingElse] => 2 [somethingThird] => 2 ) )
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
movac
  • 1,576
  • 3
  • 21
  • 45

1 Answers1

0

You are getting array data the wrong way. Get data like $myArray[0]['something'] way.

// this is wrong way 
$myArray->something;
$myArray->0;

// right way to getting array
echo "something: " . $myArray[0]['something'] . PHP_EOL;
echo "somethingElse: " . $myArray[0]['somethingElse'] . PHP_EOL;
echo "somethingThird: " . $myArray[0]['somethingThird'] . PHP_EOL;

=> Output

something: -12
somethingElse: 2
somethingThird: 2
Mukesh Singh Thakur
  • 1,335
  • 2
  • 10
  • 23