-1

I am trying to get to the [name] (either once at a time or to all of them) in the json but I don't know how to do that, I've tried fiddling a bit with the code e.g. $json->Array[0]->name, but that doesn't work. Pls help. Thank you in advance for your answers.

-HeavyMalding

The code:

//the json output after decoding:
Array ( [0] => stdClass Object ( [name] => IMG_7013.JPG [full_path] => IMG_7013.JPG [type] => image/jpeg [tmp_name] => F:\XAMPP\tmp\php7772.tmp [error] => 0 [size] => 16303899 ) [1] => stdClass Object ( [name] => IMG_7738.JPG [full_path] => IMG_7738.JPG [type] => image/jpeg [tmp_name] => F:\XAMPP\tmp\php781F.tmp [error] => 0 [size] => 9498238 ) [2] => stdClass Object ( [name] => IMG_7792.JPG [full_path] => IMG_7792.JPG [type] => image/jpeg [tmp_name] => F:\XAMPP\tmp\php786E.tmp [error] => 0 [size] => 10818478 ) ) 

1 Answers1

0

The question is not clear enough. If you want to convert a json output to array use the example below.


<?php

$json = 'your json code';
$json = json_decode($json,true);

foreach($json as $row)
{
    $name = $row['name'];
    
    echo $name.'<br>';
}

// ONE ROW

$name = $json[0]['name'];

echo $name;

?>

Riga
  • 34
  • 5
  • Please do not answer duplicate questions. This question is asked nearly everyday. We try to close and remove obvious duplicates from Stack Overflow. – mickmackusa Apr 12 '22 at 00:14
  • Thanks for the answer, it works perfectly. I didn't find an answer eventhough there were similar post to mine, so that's why I asked a separate question. There wasn't a post where you would decode a json from a file array that you get when you upload files and encode them into json. – HeavyMalding Apr 12 '22 at 11:29