Search code examples
phpmagento

How to get array of string for particulate value in PHP?


Here is my array and i get only name from that array so how can i get it

[
 {
  "name":"imgpsh_fullsize_anim_31.png",
  "type":"image\/png",
  "tmp_name":"\/tmp\/phpcaGk0O",
  "error":"0",
  "size":"34171",
  "file":"imgpsh_fullsize_anim_31.png",
  "cookie":
  {
   "name":"admin",
   "value":"s3jbpiubqq13tsrase0d4e6cma",
   "lifetime":"900000",
   "path":"\/nback",
  },
  "previewType":"image"
  }
 ]

Solution

  • I assume this is a JSON string you have in your hands so basically:

    $arr = json_decode($str, true);
    $name = $arr[0]["name"];