• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • 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