KAYA - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of KAYA.php
- <?php
- $a_all_f = array(
- 'US' => 0,
- 'EU' => 0,
- 'TAO' => 0
- );
- $a_common_f = $a_all_f;
- $a_order = array(
- 0 => array(
- 'p-sku' => 'ABC123',
- 'p-cat' => 'MANETTE',
- 'p-mapping' => array(
- 'US' => 1,
- 'EU' => 2
- )
- ),
- 1 => array(
- 'p-sku' => 'DEF456',
- 'p-cat' => 'MANETTE',
- 'p-mapping' => array(
- 'TAO' => 1
- )
- ),
- 2 => array(
- 'p-sku' => 'OOO111',
- 'p-cat' => 'ACCESSORY',
- 'p-mapping' => array(
- 'US' => 3,
- 'TAO' => 1
- )
- ),
- 3 => array(
- 'p-sku' => 'PPP222',
- 'p-cat' => 'ACCESSORY',
- 'p-mapping' => array(
- 'US' => 3,
- 'TAO' => 1
- )
- )
- );
- foreach ($a_order as $a_product) {
- //print_r($a_product);
- $a_tmp = array();
- foreach (array_intersect(array_keys($a_common_f), array_keys($a_product['p-mapping'])) as $key) {
- //print_r($key);
- $a_tmp[$key] = $a_common_f[$key] + $a_product['p-mapping'][$key];
- }
- //print_r($a_tmp);
- $a_common_f = $a_tmp;
- }
- //print_r($a_common_f);
- if (count($a_common_f) > 0) {
- // first KEY of the value-sorted array
- asort($a_common_f);
- $THE_F_TO_USE[array_key_first($a_common_f)] = "tous les sku";
- }
- else {
- // TODO il faut trier l'array pour avoir MANETTE first puis ACCESSORY
- // ou sinon, il faut faire 2 fois le foreach (laid)
- foreach ($a_order as $a_product) {
- $a_tmp = $a_product['p-mapping'];
- asort($a_tmp);
- if ($a_product['p-cat'] == 'MANETTE') {
- $THE_F_TO_USE[array_key_first($a_tmp)][] = $a_product['p-sku'];
- }
- else if ($a_product['p-cat'] == 'ACCESSORY') {
- $has_a_f_in_common = 0;
- foreach (array_keys($a_tmp) as $k_f) {
- if (array_key_exists($k_f, $THE_F_TO_USE)) {
- $THE_F_TO_USE[$k_f][] = $a_product['p-sku'];
- $has_a_f_in_common = 1;
- break;
- }
- }
- // si pas de f en commun, alors comportement par défaut : f la plus prio de l'accessoire
- if ($has_a_f_in_common == 0) {
- $THE_F_TO_USE[array_key_first($a_tmp)][] = $a_product['p-sku'];
- }
- }
- }
- }
- print_r($THE_F_TO_USE);