0

I'm using jquery to send a serialized single dimensional array to my php script.

Upon arriving at the server: The array should be transformed into a multidimensional array where every 2 values in the original array are a new row.

   $oldarray

looks like (value1, value2, value3, value4)

  $newarray =array();

Should look like

(   Value1, Value2
    Value3, Value4  )

Any suggestions?

1
  • What is the purpose of having them on new lines? That won't change how the data is handled in php. To make it a multidimensional array you would have to push each array into another. Commented Sep 1, 2013 at 4:49

1 Answer 1

1

You can use array_chunk for this:

 $newarray = array_chunk($oldarray, 2);

The first example on the linked doc page shows this exact use case.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.