• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space
  • Chevereto Support CLST

    Support response

    Support checklist

    • Got a Something went wrong message? Read this guide and provide the actual error. Do not skip this.
    • Confirm that the server meets the System Requirements
    • Check for any available Hotfix - your issue could be already reported/fixed
    • Read documentation - It will be required to Debug and understand Errors for a faster support response

[PHP] get new format of arrays

Avast

👽 Chevereto Freak
Hey guys,

i need some help/advice for formatting arrays.

Actually my arrays look like this:

PHP:
 array(array(product => 14 , amount => 4),array(product => 12 , amount => 9));

Now i want them like this:

PHP:
array('14' => array(amount => 4),'12' => array(amount => 9));


How could this be done?
I'm to deep in the code, so i'm not able to see a solution for this.
 
In PHP you always need to use quotes. You are missing the quotes around "amount".
 
Then I don't understand the question. In the first one you have implicit indexes (0, 1, etc.) and in the second one you have explicit indexes (14, 12, etc). But at the end I don't understand the question I mean what is the problem with structure A and B?
 
Yeah, sorry my brain was tired.

The simple solution for a different format of an array :

PHP:
$cart = array();
foreach ($array as $key => $value) {
    $cart[$value["product"]] = $value["amount"];
}

It takes the old array ($array) with implicit indexes and converts it into an array with explicit indexes.
 
Back
Top