-1

i have this json file with written

[
{"image_member_id":"17665","image_id":"11160","image_caption":"dalla bacheca"},
{"image_member_id":"17310","image_id":"11159","image_caption":"dalla bacheca"},
{"image_member_id":"17310","image_id":"11158","image_caption":"dalla bacheca"},
{"image_member_id":"17780","image_id":"11157","image_caption":"dalla bacheca"},
]

I call the file with

$jsondata = file_get_contents("uploads/file/file-text-dati-globali/foto-galleria/gallery.json");
$json_a = json_decode($jsondata);

how can i download user ids only image_member_id 17310

{"image_member_id":"17310","image_id":"11159","image_caption":"dalla bacheca"}, {"image_member_id":"17310","image_id":"11158","image_caption":"dalla bacheca"}, i am using foreach but i download all records, i just want to download id 17310

  • Decode it to an associative array (check the json_decode manual page for how to do that). Once you've done that, there are soooo many answers to this already (and it's absolutely nothing to do with JSON - once you've decoded the data, it's just a regular old PHP multidimensional associative array which you can search in. The fact that it used to be JSON is completely irrelevant.). – ADyson Nov 24 '21 at 15:36
  • 6
    https://stackoverflow.com/questions/1019076/how-to-search-by-key-value-in-a-multidimensional-array-in-php, https://stackoverflow.com/questions/8102221/php-multidimensional-array-searching-find-key-by-specific-value, https://stackoverflow.com/questions/6661530/php-multidimensional-array-search-by-value, https://stackoverflow.com/questions/42397219/php-search-multidimensional-array-for-value, https://stackoverflow.com/questions/10152920/php-multidimensional-array-get-values, and so on. You can easily find more with some simple searches – ADyson Nov 24 '21 at 15:37

1 Answers1

0

You can use array_filter to achieve this

$json_a = json_decode($jsondata, true); //associative array
$id_search = 17310;
$results = array_filter($json_a, function($v, $k) use ($id_search) {
    return $v['image_member_id'] == $id_search;
}, ARRAY_FILTER_USE_BOTH);
mt.i.1
  • 115
  • 7