0

I have the following:

Array ( [0] => Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) ) )

I need to get the value "150109", but how on earth do I accomplish that?

Nissa
  • 4,636
  • 8
  • 29
  • 37
oivindr
  • 3
  • 1
  • `$data[0][0]["value"]` or `$data[0][0]["safe_value"]` if the `$data` is your array – M A SIDDIQUI Feb 16 '17 at 13:27
  • did you try googling for an answer? You should be able to find [other answers](http://stackoverflow.com/questions/17139453/php-accessing-multidimensional-array-values) on accessing multidimensional array values. – mickadoo Feb 16 '17 at 13:45

2 Answers2

2

Top level:

print_r($data);
// Output: Array ( [0] => Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) ) )

Outmost element:

print_r($data[0]);
// Output: Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) )

Next level:

print_r($data[0][0]);
// Output: Array ( [value] => 150109 [format] => [safe_value] => 150109 )

The final value

echo $data[0][0]['value'];
// Output: 150109

Accessing each layer of values this way makes it easier to figure out how to get to your desired value. After a while this becomes more obvious.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • Only the first one (top level) will actually output someting. So print_r($data); gives me: Array ( [und] => Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) ) ). This construction looks a bit different from my initial array. – oivindr Feb 16 '17 at 13:56
  • @oivindr Then you have different data than in your example. However, to get the value in that array, you would do `$data['und'][0]['value']`. – OptimusCrime Feb 16 '17 at 13:57
  • Thank you! I need to clean up my code, but it looks like it's working. BTW, I got the first array constructin when I used: print_r(array_values($artnr)); Not sure why they differ. – oivindr Feb 16 '17 at 14:16
  • It should not. Please accept my answer if it solved your problem. – OptimusCrime Feb 16 '17 at 14:17
  • @oivindr Please click the `v` under the up/down-votes to this question to mark it as the correct solution. Indicating that this answer helped you makes it easier for people who may have a similar problem in the future. – OptimusCrime Feb 16 '17 at 14:26
0

You can use get values of arrays continusly on multidimensional arrays:
$value = $array[0][0]["value"];

Ad5001
  • 748
  • 5
  • 19