Help me.. |
someone help me.. i just stucked and cant get any idea how too do it.
Source array: ["data"] => array(10) { ["type"] => string(10) "controller" ["name"] => string(3) "eg1" ["description"] => string(5) "desc1" ["type2"] => string(8) "function" ["name2"] => string(2) "c2" ["controller2"] => string(4) "welcome" ["description2"] => string(6) "desc 2" ["type3"] => string(10) "controller" ["name3"] => string(2) "c3" ["description3"] => string(8) "c3 descr" } from the above array how can i get new array like: array( array( 'type' => 'controller', 'name' => 'eg1', 'description' => 'desc1' ), array( 'type' => 'function', 'controller' => 'welcome', 'name' => 'c2', 'description' => 'desc 2' ), array( 'type' => 'controller', 'name' => 'eg1', 'description' => 'desc1' ), array( 'type' => 'controller', 'name' => 'c3', 'description' => 'c3 descr' ) ); data is submitted through a https://github.com/tristandenyer/Clone-s...ing-jQuery thanks for help
Why not use array input fileds like <input type="text" name="type[]" />? Then you will get post data wich hold 4 arrays, one for each fieldname (type,name etc).
The number of entries in those arrays is the same as the amount of times the form hs been cloned and the keys between the arrays will corresponed so you can link them easely to create the array type you need. (01-04-2016, 03:52 PM)Diederik Wrote: Why not use array input fileds like <input type="text" name="type[]" />? Then you will get post data wich hold 4 arrays, one for each fieldname (type,name etc). Do you have an exemple for me
Or loop through your data in php. Use a counter to add the 1,2,3 to the end of the default type, name, description variables, and create your array from the data you have.
PHP Code: <?php (01-05-2016, 06:50 AM)PaulD Wrote: Or loop through your data in php. Use a counter to add the 1,2,3 to the end of the default type, name, description variables, and create your array from the data you have. Sorry but this is a horrible idea.
Why? It turns his array into the array he wanted?
I was just trying to help... but out of interest, why is it horrible? Paul.
(01-05-2016, 06:50 AM)PaulD Wrote: Or loop through your data in php. Use a counter to add the 1,2,3 to the end of the default type, name, description variables, and create your array from the data you have. many many thanks.....
Ah, ok, it is, and I would not have a clunky solution like that in my code.
But I got the impression from the question that he was using an external system to generate the array, that I guessed he was having trouble with as Diederik's answer was good. So, if you have a messy array, and need it in another format, and was not sure how to do it, or alter how you are getting the array in the first place, I think my answer is a good possible solution for the problem described. Yes it is a lot of code, with flags, little error checking etc. But if a rejig of an array gets you out of a tricky corner how else can you do it. Anyway, I think 'horrible' made me think you thought I had done something wrong in the code. Perhaps next time you call someones code 'horrible' you could either temper your vocabulary or add some qualification to it. As I said, was just offering an answer to someone who said they were stuck, in the hope of helping, not proposing super efficient power coding as an entry into a coding competition. Best wishes, Paul :-( |
Welcome Guest, Not a member yet? Register Sign In |