KanaTronix Posted September 29, 2014 Share Posted September 29, 2014 Hey guys. I am creating an application that require dynamic fields generated by javascript. I have managed to create the forms the database and pretty much may things. I come to hit a roadblock with this array problem. I am trying to get the data from the browser by checking which one contain more than one value and then transverses through another array this one $nyingi = [ 'location_' => ['text' => 'loc_txt','priority' => 'loc_order'], 'photo_' => ['path' => 'p_txt'], 'video_' => ['path' => 'v_txt'], 'product_' => ['p_id' => 'pt_q', 'text' => 'pt_txt', 'expire' => 'pt_xpr', 'title' => 'pt_tt'], 'service_' => ['p_id' => 'st_q', 'text' => 'st_txt', 'expire' => 'st_xpr', 'title' => 'st_tt'], 'hours_' => ['time1' => 't1', 'time2' => 't2', 'type' => 'tt'], 'map_' => ['text' => 'm_txt'] ]; use this loop foreach($nyingi as $ins => $vl){ foreach($vl as $fld => $box){ $uwazi = $this->input->post($box); if(is_array($uwazi) && 1<count($uwazi)){ foreach($uwazi as $bb){ $one[$ins][$fld][] = $bb; } } } } and get this result Array ( [location_] => Array ( [text] => Array ( [0] => Main Office [1] => Branch 1 [2] => Branch 2 ) [priority] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) [photo_] => Array ( [path] => Array ( [0] => Photo 1 [1] => Photo 2 [2] => Photo 3 ) ) [video_] => Array ( [path] => Array ( [0] => Video 1 [1] => Video 2 [2] => Video 3 ) ) what I want to get is this Array ( [location_] => Array ( [text] => Main Office [priority] => 1 ) [photo_] => Array ( [path] => Photo 1 ) [video_] => Array ( [path] => Video 1 ) [product_] => Array ( [p_id] =>Product 2 photo [text] => Product 2 Description [expire] => Product 2 expire [title] => Product 2 ) ) ) for each one of those. Any ideas where I am getting wrong. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 29, 2014 Share Posted September 29, 2014 Sorry but your code loop is far too advanced me. I have had no experience of code that processes an array and produces output from an alternate reality. Quote Link to comment Share on other sites More sharing options...
KanaTronix Posted September 29, 2014 Author Share Posted September 29, 2014 Sorry but your code loop is far too advanced me. I have had no experience of code that processes an array and produces output from an alternate reality. Any input is deeply appreciated. What I want to get is what's important if you have an idea just write man. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 30, 2014 Share Posted September 30, 2014 As Barand said - this is very confusing and makes no sense to an outsider. That said let me ask. How did you get the first array? Seems to be very organized and makes sense, but then you have that crazy code trying to manipulate it (I think) and you ask how to morph it into a second array structure. Why do you wish to do this? IMHO - people rely on arrays way too much. And structures this deep are just begging to be re-analyzed and avoided. Again - IMHO. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 30, 2014 Share Posted September 30, 2014 Any input is deeply appreciated. What I want to get is what's important if you have an idea just write man. The content of the output produced by your code bears no relation to the content of what you claim is the input array. So I am not going to struggle with trying to work out what you are trying to do and how the data should be manipulated. Quote Link to comment Share on other sites More sharing options...
Solution KanaTronix Posted October 1, 2014 Author Solution Share Posted October 1, 2014 Thanks for the replies. But I have managed to fix it. it was so simple and make me wonder how stupid I am. I fix the loop and be like this foreach($nyingi as $ins => $vl){ foreach($vl as $fld => $box){ $uwazi = $this->input->post($box); if(is_array($uwazi) && 0<count($uwazi)){ $q=0; foreach($uwazi as $bb){ $one[$ins][$q][$fld] = $bb; $q++; } } } } The inputs are from a dynamic form form with multiple dynamic fields. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.