0

I am working with large product data API. I am getting a large number of product data in the form of a Multi dimension array.

In my code, I have 130 Categories. Every category has some number of Products listed under it. The product listing I am getting is as below (I copied some portion of my array):

    Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [product_id] => 10295
                    [sku] => BDK Motor
                    [name] => Motor 2005 VW Golf V 5 1K 2,0 SDI Diesel BDK 75 PS 55 KW
                )

            [1] => Array
                (
                    [product_id] => 10502
                    [sku] => BDK Motor-2
                    [name] => Motor 2005 VW Golf V 2,0 SDI BDK 55 KW 75 PS 
                )

            [2] => Array
                (
                    [product_id] => 15693
                    [sku] => CAY Motor
                    [name] => Motor 2009 VW Audi Polo Touran Roomster Golf Leon 1,6 TDI CAY CAYA DE15693
                )

            [3] => Array
                (
                    [product_id] => 17662
                    [sku] => AGR Motor 
                    [name] => Motor 1999 VW Audi Skoda Seat Golf A3 8L Octavia 1,9 TDI Diesel AGR
                )

            [4] => Array
                (
                    [product_id] => 18980
                    [sku] => ZJ-VEM Motor 
                    [name] => Motor 2009 Mazda 2 II DE 1,3 Benzin 55 KW 75 PS ZJ-VEM
                )
    [1] => Array
        (
            [0] => Array
                (
                    [product_id] => 18245
                    [sku] => 08649262 Motorhalter-4
                    [name] => Motorhalter Ford Focus II DA 2,5 ST 166 KW 225 PS HYDA 08649262 SCHROTT
                )

            [1] => Array
                (
                    [product_id] => 24041
                    [sku] => 8D0199335N Halter 
                    [name] => Halter Anschlag Audi 80 A4 Seat Ibiza VW Caddy Passat Golf 1,9 TDI 1Z 8D0199335N
                )

            [2] => Array
                (
                    [product_id] => 24472
                    [sku] => 9639593380 Halter-1
                    [name] => Halter Peugeot Citroen Berlingo C5 Xantia 206 307 2,0 HDI RHY DW10TD 9639593380
                )

            [3] => Array
                (
                    [product_id] => 24606
                    [sku] => 2247711 Motorhalter-3
                    [name] => Motorhalter Halter Rover MG ZT ZT-T 75 RJ 2,0 CDTi 131 PS 204D2 2247711
                )

            [4] => Array
                (
                    [product_id] => 24613
                    [sku] => 204D2 Halter-5 
                    [name] => Halter Halterung Träger Rover MG ZT ZT-T 75 2,0 CDTi 131 PS 204D2
                )

And this array lasts up to 75 array keys with each key having average 80-90 products.

I want to get output like if key[0] have 100 items and key[1] have 90 items so in resultant array after 1st 100 items next items of key[1] appends as [101]; [102];....and so on.

To clear my problem, I need output like below:

Array(
[0]=>
[1]=>
[2]=>
.
.
.
.
[109]=>
.
.
.
[nth key]=>)

1 Answer 1

2

PHP lack array_flatten function but you can compose it like

 array_reduce($array, 'array_merge', [])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.