Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

element not added when push in array

I’m trying to push an array into other array but it does not work. Also, i have tried with array_push and does not work

    foreach($cartitemCollection as $cartitem){
        foreach($cartitem['product'] as $product){
            $variablePrices = $variablePricesRepository->findByProductId($product['id']);
            $product['var_price'] = $variablePrices; //not working
            array_push( $product,$variablePrices ); //also not working
        }   
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

On next iteration product will be overwritten. But you can use a reference. Note the ampersand.

foreach($cartitemCollection as $cartitem){
    foreach($cartitem['product'] as &$product){
        $variablePrices = $variablePricesRepository->findByProductId($product['id']);
        $product['var_price'] = $variablePrices;
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading