Generating a key=value pair in a for-loop

Hi everyone

i am trying to access the values in a dynamic array that was obtained from a http post object.

for example, i want to access the £80.00 figure below

i.e the £80.00 figure is contained in a subarray that holds a value=key of amountString

    [12] => Array
            [0] => amountString
            [1] => £80.00

   [13] => Array
        [0] => name
        [1] => testname


this is how i generated this array. i got it from a http object i.e:

POST /fail?installation=XXXXXX&msgType=authResult HTTP/1.0
 Content-Type: application/x-www-form-urlencoded;charset=UTF-8
 Content-Length: 973
 User-Agent: WJHRO/1.0 ( HTTP Request Object)


i then did the following to get the array:

$data = explode('&', $post);

            foreach($data as &$entry) {
                 $entry = explode('=', $entry);
                 $entry[1] = urldecode($entry[1]);

i know that i can access an array like this:


the problem is that the number change. so, it would not be accurate to use this number system.

is there a better way to do it.

i suspect that the problem is in my forloop. the forloop renders the array into numbers rather than as key-value array.

So… you’re getting POST values. Why… do you not just reference them directly from the $_POST array?

hey Starlion.
thanks for reply.

i am not sure how to access them directly, i mean. the values don’t come back as a PHP Array. they come back as a json object. you will note that i had to remove the & and also place the values in an array.

is it possible to access them directly using PHP

For starters, that’s not a json object.

Second of all, this is a post-reply from an external website? And the CONTENT is a URL-Querystring? [fphp]parse_str[/fphp]

Thanks StarLion

That is perfect. i was not aware about the parse_str function. It now works perfectly.