0

I'm dealing with this array, but the key [row_204] changes each time (ie sometimes it is [row_79] or [row_109]) but all other key names stay the same in this exact structure. I need to get the value of UUID and userID but can't find a solution to get the value by key in that [row_] array.

I need to be able to extract the values and place them in strings, for example,

$uuid =

and so on.

I can't seem to find a similar query and have tried so many variations. Many thanks in advance.

Array
(
[action] => edit
[data] => Array
    (
        [row_204] => Array
            (
                [UUID] => 148367FF-FBEB-413D-8495-6B1539BDC5DC
                [userID] => 7
                [maxPoints] => 7
                [awardedPoints] => 6
                [Date] => 2017-06-08
            )

    )

)
3
  • Is it always only one entry? e.g. only one row_* key? Commented Jun 8, 2017 at 13:21
  • Hi, yes. The above structure is identical in each case, just the row_ value changes Commented Jun 8, 2017 at 13:34
  • Did you give up or what? Commented Jun 29, 2017 at 18:32

2 Answers 2

1

If you know there is always only one row_* item in that array, you can just pull the first item (i.e., the only one in your case) off the front of the list with array_shift():

$data = array_shift($array['data']);
print_r($data);

Will give you:

Array (
    [UUID] => 148367FF-FBEB-413D-8495-6B1539BDC5DC
    [userID] => 7
    [maxPoints] => 7
    [awardedPoints] => 6
    [Date] => 2017-06-08
)

Then you can just deference the keys you want:

$uuid = $data['UUID'];
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for sucha speedy reply. The whole array is arriving in the form of a $_POST. When I use $data = array_unshift($_POST['data']); I get an error PHP Warning: array_unshift() expects at least 2 parameters, 1 given
That was an error, it is array_shift(), not array_unshift(), @Alex Howansky already corrected it.
Yeah sorry, heh, I always get those backwards. My brain wants to think of something spelled "un-" as destructive, not constructive.
0

The easiest would probably be:

$data = current($_POST['data']);

Then just echo $data['UUID'];.

If you need the key for whatever reason:

list($key, $data) = each($_POST['data']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.