0

I think I have a supplement question. If irrelevant , then sorry in advance.

I have nested array in post like: from apache web server page index.php

$_POST['colorsarray'][0] = '#ff0000';
$_POST['colorsarray'][1] = '#2d67ea';
$_POST['colorsarray'][3] = '#7cf325';
$_POST['mode'] = 'none';
$_POST['singlecolour'] = '#ff0000';

Can you suggest me how to assign this array (coloursarray) directly to another array in espwebserver. In other use cases , only the list (length) of array will increase and is not know until the variable arrives from client.

Thanks in advance.

1

The ability for PHP to do this is special to PHP. The PHP program parses the field names as PHP arrays if they are named thus:

<form ....>
<input name="[colorsarray][0]" value="#ff0000" />
<input name="[colorsarray][1]" value="#2d67ea" />
<input name="[colorsarray][2]" value="#000000" />
<input name="[colorsarray][3]" value="#7cf325" />
[...]
</form>

But since the ESP8266's core doesn't use PHP or understand PHP arrays, you will have to use the literal field name [colorsarray][3], parse it yourself, and determine at run-time the length of the array and how much memory is needed, etc.

1
  • Thanks for the help, So I need to take care of the length of array at runtime and have to manually parse the array data. Note: not using form data just using ajax to collect data and send typically array of hex colours. But cannot change or resolve the array into any other convenient form, so stuck with arrays for now. I had the ultimate resolution as to use indices for the array but was here to be sure that there is not any KISS (keep it simple silly) method available.
    – S.M.
    Mar 24 '18 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.