redarrow Posted December 21, 2008 Share Posted December 21, 2008 He wants the values off this done <input value="Ny" name="Country[Ny][]" /> <textarea name="Country[Ny][0]"></textarea> but it to hard to do what he wants like that some one show me a an saw then ive never in my life seen a array of Country[0] turned into another array then merged never. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720802 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 THIS CODE DOES NOT WORK THE WAY YOU WANT IT ..... SEE YOUR SELF....... <form method="POST"> <input type="text" name="Country[Ny][]"></textarea> <textarea name="Country[Ny][0]"></textarea> <input type="submit" /></form> <?php $Country = $_POST['Country']; $ry=($Country[Ny][0]); $p=array($ry); foreach($p as $res){ $r = nl2br($res); $b=explode('<br />',ltrim($r)); $result=array_merge($b,$Country); print "<PRE>"; print_r($result); print "</PRE>"; } ?> as you can seethe result's are wrong what you want. Array ( [0] => JOHN [1] => JOHN [2] => JOHN [Ny] => Array ( [0] => JOHN JOHN JOHN ) ) Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720807 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 He wants the values off this done <input value="Ny" name="Country[Ny][]" /> <textarea name="Country[Ny][0]"></textarea> but it to hard to do what he wants like that some one show me a an saw then ive never in my life seen a array of Country[0] turned into another array then merged never. Thanks for your help, I appreciate it. I Will have an answer soon I think, And il post it, Ive easily spent over 5 hours on this shit, Im not giving up now Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720808 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 THIS CODE DOES NOT WORK THE WAY YOU WANT IT ..... SEE YOUR SELF....... <form method="POST"> <input type="text" name="Country[Ny][]"></textarea> <textarea name="Country[Ny][0]"></textarea> <input type="submit" /></form> <?php $Country = $_POST['Country']; $ry=($Country[Ny][0]); $p=array($ry); foreach($p as $res){ $r = nl2br($res); $b=explode('<br />',ltrim($r)); $result=array_merge($b,$Country); print "<PRE>"; print_r($result); print "</PRE>"; } ?> I will try to mess with this if my attempt doesnt work, I think I nearly have it, Thx again Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720809 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 You the best programmer in the world then, Because your trying to create a array out off the 0 element of a existing array, NEVER like to see that.. WAITING. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720811 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 FUCK YEHHHH!!!!!!!!!!! I FINALLY DID IT. 8) 8) <form method="POST"> <input value="Ny" name="Country[Ny][]" /> <textarea name="Country[Ny][0]"></textarea> <input value="Ca" name="Country[Ca][]" /> <textarea name="Country[Ca][0]"></textarea> <input type="submit" /></form> <?php $Country = $_POST['Country']; print "<PRE>"; print_r($Country); print "</PRE>"; foreach($Country as $CountryId) { while($CountryId = current($Country)) { $New = implode("\n",$CountryId); $New = explode("\n",$New); foreach($New as $Key) { unset($Country[key($Country)][0]); array_push($Country[key($Country)],$Key); } next($Country); } } print "<PRE>"; print_r($Country); print "</PRE>"; ?> OUTPUT Array ( [Ny] => Array ( [1] => FUCK [2] => YES [3] => I ) [Ca] => Array ( [1] => THINK [2] => I [3] => DID [4] => IT ) ) Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720824 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 I get this theo. Array ( [Ny] => Array ( [0] => john john john ) [Ca] => Array ( [0] => john john john ) ) Array ( [Ny] => Array ( [1] => john [2] => john [3] => john ) [Ca] => Array ( [1] => john [2] => john [3] => john ) ) Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720828 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 Look at the bottom arrays, Its worked. (The top array is the first print_r) (The bottom is the print_r after the loops,) I just tested with much more contries and its working, **** **** YEH!! Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720830 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 but what the two top ones for then...... Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720831 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 but what the two top ones for then...... Remove the first Print_r, It was only here for you to see what was happening. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720832 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 well done, but i want a full explanation of your code now lol. tell us what you done it all good. step by step explain every function looks good. it blown my mind and a fuse... Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720835 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 Was this the order you done. Someone cut it more down so i understand it more cheers. <form method="POST"> <input value="Ny" name="Country[Ny][]" /> <textarea name="Country[Ny][0]"></textarea> <input value="Ca" name="Country[Ca][]" /> <textarea name="Country[Ca][0]"></textarea> <input type="submit" /></form> <?php // posted the varable country. $Country = $_POST['Country']; // loop the country as countryid foreach($Country as $CountryId) { // while loop countryid via the current value while($CountryId = current($Country)) { //implode the cuntryid $New = implode("\n",$CountryId); // explode countryid $New = explode("\n",$New); //foreach new s key foreach($New as $Key) { //unset country as key 0 unset($Country[key($Country)][0]); //ush off the las element of country array_push($Country[key($Country)],$Key); } // move to next pointer. next($Country); } } //print the results. print "<PRE>"; print_r($Country); print "</PRE>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720844 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 well done, but i want a full explanation of your code now lol. tell us what you done it all good. step by step explain every function looks good. it blown my mind and a fuse... hahaha, I think already I am confused by it, Their is too many loops to track for me, This is the first time I used multidimensional array But Basically what is happening is foreach($Country as $CountryId) { INSIDE COUNTRY ARRAY (NY AND CA) while($CountryId = current($Country)) { $New = implode("\n",$CountryId); $New = explode("\n",$New); WHILE WE ARE INSIDE NY ARRAY, CONVERT THE ARRAY TO A STRING, THEN CONVERT BACK TO ARRAY foreach($New as $Key) { unset($Country[key($Country)][0]); array_push($Country[key($Country)],$Key); } WHILST WE ARE IN NY, WE UNSET THE [0], ([0] = the value with no line break) FOR EACH KEY INSIDE NY Array, ADD TO THE CURRENT SELECTED ARRAY(WHICH IS NY) next($Country); } NOW WE ARE BACK INTO THE MAIN ARRAY LOOP, WE HAVE ADDED ALL KEYS AND VALUES IN THE NY ARRAY TO NY, SO WE GO NEXT, INTO THE CA ARRAY, AND THEN THE LOOP GOES THROUGH IT ALL AGAIN. } Sorry for the caps, Hope you understand it now and can maybe use this in future. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720846 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 Well i ve never seen a new php programmer get it write first time, well done, ill have to investigate your code syntax very good. I need to learn lol. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720855 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 Well i ve never seen a new php programmer get it write first time, well done, ill have to investigate your code syntax very good. I need to learn lol. Thanks haha, But I really didnt get it right first time, I have been trying for many hours now First I gave up a few days ago and made all seperate variables, But then yesterday I wanted to try again. Then today I spent around 4-5 hours of editing and remaking the code etc. I tried over 15 array fucntions over and over again, haha, Some I didnt even know before. If I didnt get it eventually, I would of broke my PC I think. Btw, I noticed you are from London, are you employed as a php programmer? php Jobs are hard to get in london, I live there too. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720863 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 No i do programming from home no boss lol, But to be honest the better you are people hire you throw the net. but programming is hard. html xhtml css javascript/ajax seo php mysql that the beginning then advance php meaning OOP then the dreaded seo then we look at a book that says 24hours ye wright.. Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720868 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 No i do programming from home no boss lol, But to be honest the better you are people hire you throw the net. but programming is hard. html xhtml css javascript/ajax seo php mysql that the beginning then advance php meaning OOP then the dreaded seo then we look at a book that says 24hours ye wright.. Haha, Yeh the 24 hour book is funny, Its possible to read all in 24 hour, But then wen u wake up the next day, Its all forgotten. I only know Html Css Php(intermediate) SEO Im just starting to learn javascript, can you recommend some good books? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720872 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 good tutorials. http://www.freewebmasterhelp.com/tutorials/javascript http://www.w3schools.com/JS/default.asp All i no sorry. Get all my books and cd's from ebay or amazon sorry. there so many ill be here all day lol. best php book big hard book php black book beginning php 5 have a look on amazon sorry. Dont recommend books it changes so quickly just use php.net Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720878 Share on other sites More sharing options...
UpcomingPhpDev Posted December 21, 2008 Author Share Posted December 21, 2008 Ok thx, Il checkout those Js links, ANd maybe the php books Laters Quote Link to comment https://forums.phpfreaks.com/topic/137898-solved-adding-to-multidimensional-arrays-frustrating/page/2/#findComment-720881 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.