Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,831 members, 7,810,200 topics. Date: Friday, 26 April 2024 at 11:14 PM |
Nairaland Forum / Science/Technology / Programming / Array Conversion In PHP (987 Views)
Java Array Problem / Can An Array In Java Hold Multiple Types? / What The Different Between ENUM And ARRAY In Java (2) (3) (4)
Array Conversion In PHP by Dlastofmykind(m): 11:07am On Oct 31, 2015 |
Good day.
I'm having issues converting this array to an associative array. The array is in this format: [10] => Array ( [0] => Nigeria ) [11] => Array ( [0] => South Africa ) [12] => Array ( [0] => Spain ) [13] => Array ( [0] =>England ) [14] => Array ( [0] => Germany ) [15] => Array ( [0] => Mali ) and i want it to be converted to this format: [10] => Array ( [0] => Nigeria [1] => South Africa [2] => Spain [3] =>England ) [11] => Array ( [0] => Germany [1] => Mali ) Please how can it be done? Thanks |
Re: Array Conversion In PHP by Adesege(m): 12:36pm On Oct 31, 2015 |
What code have you tried? Can you post the code that generated the first code so I can have a look?? What programming language are you using also? |
Re: Array Conversion In PHP by Dlastofmykind(m): 12:57pm On Oct 31, 2015 |
The code is lengthy. many lines of codes. The above snippet is just like an illustration of how the array will be displayed but the concept of converting it to the oda array is what I'v not really figured out. |
Re: Array Conversion In PHP by Nobody: 2:56pm On Oct 31, 2015 |
Use array_chunk to fix this... |
Re: Array Conversion In PHP by Dlastofmykind(m): 3:28pm On Oct 31, 2015 |
Jregz:Ok. Thanks |
Re: Array Conversion In PHP by Adesege(m): 4:14pm On Oct 31, 2015 |
Dlastofmykind: Does that help?? If not, you can rewrite the code to show where you are having problem and paste here. I cant work on abstract |
Re: Array Conversion In PHP by thewebcraft(m): 11:48pm On Oct 31, 2015 |
try array_values function: $array = array_values($myarray); 1 Like |
Re: Array Conversion In PHP by makavele: 1:18am On Nov 01, 2015 |
Dlastofmykind: no matter how long, it is always good to provide visuals . . cos you could have made a very tiny error (not even in the arrays function) . . that would kill the whole fin . . . meanwhile . . you can use multi-dimensional arrays . . . a working example below: <?php and it will output the following: African countries include the following: Nigeria, Mali, Egypt and Ghana. |
(1) (Reply)
Need A Male Or Female Web Developer / You Want To Build A Career In Mobile Application Development? / Stop Waiting Start Developing
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18 |