0
[["pdf-sample.pdf",["uploads\/28\/pdf-sample.pdf"],{"en":"PDF Sample"},"","28"],["pdf-sample2.pdf",["uploads\/29\/pdf-sample2.pdf"],{"en":"Second PDF sample"},"","29"]]

Now I know how to access uploads\28\pdf-sample.pdf part - just type $value[1][0], but I need to get the description of that file, which is PDF Sample - and how can I access that?

My code thus far:

$files = json_decode($p['file']);
foreach ($files as $value) {
   echo $value[1][0].'<br />';
}
5
  • your_array[0][2].en will give you "PDF Sample". "uploads\28\pdf-sample.pdf" is at your_array[0][1] not [1][0] as said in your question. Commented Jun 9, 2015 at 16:58
  • That looks the PHP, and the answer depends on whether you decoded the json into objects or associative arrays. Commented Jun 9, 2015 at 16:59
  • @RafH sadly, that doesn't return anything. Commented Jun 9, 2015 at 17:06
  • @RafH the . notation you used is for JS not PHP Commented Jun 9, 2015 at 17:13
  • possible duplicate of PHP grab json exchange rate value from API response Commented Jun 9, 2015 at 17:17

1 Answer 1

1

You are decoding it as an object so to access the en value you need to do something like

$files = json_decode('[["pdf-sample.pdf",["uploads\/28\/pdf-sample.pdf"],{"en":"PDF Sample"},"","28"],["pdf-sample2.pdf",["uploads\/29\/pdf-sample2.pdf"],{"en":"Second PDF sample"},"","29"]]');

    foreach ($files as $value) {
        echo $value[2]->en.'<br />';
    }
Sign up to request clarification or add additional context in comments.

2 Comments

@Xeen the code I provided works ... if this doesn't work with your code you need to provide more code, specifically where you are getting $p['file']
Ah, you're right, my bad :) I had mistyped your code. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.