0

I have an array as follows:

[STATUS] => Array
   (
             [Information] = A
             [More Info ] = B
   )
[GPU0] => Array
   (
             [GPU] => 0
             [INFO] => 100
   )

Looking to use PHP to show [INFO] results. Right now I have something like this:

$array = print_r($result, true)."\n";
echo $array['GPU0']['GPU'];

My results are as follows:

Illegal string offset 'GPU0' in /var/www/somethinghere.php on line 117
1
  • What is $result, a string? Why would you use print_r to access the array? Commented Feb 15, 2014 at 20:40

1 Answer 1

2

$result is an array, $array is a string that contains what print_r would have printed. You should do:

echo $result['GPU0']['GPU'];

DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, this returns the result of the array in its entirety, sorry if my question was unclear. What I'm going for is to return the result of ['GPU'] which is "0"
It should just print the contents of that one element, not the whole array.
See the demo I just created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.