Array Conversion In PHP - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Array Conversion In PHP (1129 Views)
| Array Conversion In PHP by Dlastofmykind(op): 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(op): 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(op): 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); |
| Re: Array Conversion In PHP by makavele: 1:18am On Nov 01, 2015*. Modified: 1:51am 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: <?phpand it will output the following: African countries include the following: Nigeria, Mali, Egypt and Ghana. |
Java Array Problem • Can An Array In Java Hold Multiple Types? • What The Different Between ENUM And ARRAY In Java • 2 • 3 • 4
Sales And Installations Of Wallpaper And 3D Wall Panels • A Simpler Website Testing Tool Is Launched By Google Targeting Small Businesses • P2P Site Web Designers, Based In Kogi, Makurdi,abuja
