lundi 31 décembre 2018

Cannot Assign Key => Value to Foreach Array

I have the following array of countries ($countryIso = array("US","BR","CL");) and my idea is to create a new array to display the following schema:

('US', 200)

I tried to create the following structure:

    $countryIso = array("US","BR","CL");

    foreach ($countryIso as $isocode) {
        $productcalc[] = "'" . strtoupper($isocode) . "'" . ',' . number_format($this->product->calculate($product = $product, $countryIso = $isocode), 0, '.', ',');
    }

Despite I can create a look alike format, I realized that the array is not well formed. When I checked the output displays the following:

Array ( [0] => 'US',200

being the key is [0] and not US.

Any idea of how can I create a key => value result with

Array ( [US] => 200

using the foreach structure in my code? I tried with variants like array_combine to combine countryIso array with productcalc array but with no success



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2SuTRvZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire