0

I have a PHP array and I would like to construct similar array in Java.

I have tried using Java arrays, maps and even ArrayList but they didn't gave me the exact structure as in the PHP sample.

Below is the PHP Array Sample:

[name] => Array
    (
        [0] => shoes
        [1] => canvas
    )

What I need is a Java construct which when sent to a PHP script, the script should be able to format it just like the above.

  • 1
    See here https://stackoverflow.com/questions/11097592/convert-array-php-to-java possible duplicate question... – Christian Abdilla May 22 '17 at 13:35
  • 4
    Possible duplicate of [Convert array php to java](https://stackoverflow.com/questions/11097592/convert-array-php-to-java) – tima May 22 '17 at 13:35
  • 1
    What have you already tried? Please provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Sergey May 22 '17 at 13:36
  • what have you tried?... im kinda confused.. do you need the PHP format ? if thats the case, try `$arr = ["name" => ["shoes","canvas"]];` – CodeGodie May 22 '17 at 13:41
  • You're asking to convert a data structure from one language to another - it's not possible with an agreed interchange format of some sort. This could be JSON, XML, CSV, YAML, or any number of others. Pick whichever one best suits your needs. – iainn May 22 '17 at 13:43
  • @CodeGodie the sample PHP array above is a php server log of post from a php web application, i need to post the same data from a java application to the same php script. i have used array, map, jsonarray and arrayList to hold the data and send to the same PHP script. but the log is not same as above – user3855323 May 22 '17 at 14:42
  • 1
    so you need Java code correct? I dont work with Java, but I think you should work with JSON. From Java, turn your array into JSON and send it to PHP. PHP will convert that back to an array. – CodeGodie May 22 '17 at 14:44

0 Answers0