検索
ホームページバックエンド開発PHPチュートリアルPHP計算割引情報、アルゴリズムを計算してください。

PHP は優待情報を計算します。アルゴリズムを計算してください。

PHP コード
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$arr=array('item_info_list' => Array
                                (
                                    '0' => Array
                                        (
                                            'sku_id' => '1003244250',
                                            'ware_id' => '1001418658',
                                            'jd_price' => '269.00',
                                            'sku_name' => '百事PEPSI 男式板鞋 2012新款夏季透气舒适男款经典休闲板鞋 猎人绿 40',
                                            'outer_sku_id' => '40872121106',
                                            'product_no' => '872121101 872121102 872121104 872121105',
                                            'gift_point' => '0',
                                            'item_total' => '1',
                                        )
                                    ,
                                    '1' => Array
                                        (
                                            'sku_id' => '1003244255',
                                            'ware_id' => '1001418658',
                                            'jd_price' => '269.00',
                                            'sku_name' => '百事PEPSI 男式板鞋 2012新款夏季透气舒适男款经典休闲板鞋 暗红 39',
                                            'outer_sku_id' => '39872121105',
                                            'product_no' => '872121101 872121102 872121104 872121105',
                                            'gift_point' => '0',
                                            'item_total' => '1',
                                        )

                                )
                            ,
                            'coupon_detail_list' => Array
                                (
                                    '0' => Array
                                        (
                                            'order_id' => '213978711',
                                            'sku_id' => '1003244250',
                                            'coupon_type' => '30-单品促销优惠',
                                            'coupon_price' => '170.00',
                                        )
                                    ,
                                    '1' => Array
                                        (
                                            'order_id' => '213978711',
                                            'sku_id' => '1003244255',
                                            'coupon_type' => '30-单品促销优惠',
                                            'coupon_price' => '170.00',
                                        )

                                )
)


実際の価格を計算するアルゴリズムを要求してください。 'item_info_list' サブ配列、'coupon_detail_list' サブ配列 割引情報
は 1 つだけあり、'item_info_list' のサブ配列には製品 'coupon_detail_list' が 1 つだけあり、割引情報が存在しない場合があります。サブ配列「item_info_list」のサブ配列に商品「coupon_detail_list」が 2 つだけあり、割引情報しかない場合もあります。また、「item_info_list」サブ配列と「coupon_detail_list」サブ配列に商品が 2 つしかない場合もあります。 -array には 2 つの割引情報があります。案内をお願いします。




-----解決策---------
最終的な結末はどうなるのでしょうか?
------解決策------------------
//最初に前処理します
foreach($arr['item_info_list'] as $v) $item_info_list[$v['sku_id']] = $v;
foreach($arr['coupon_detail_list'] as $v ) $coupon_detail_list[$v['sku_id']] = $v;


foreach($item_info_list as $k=>$v)
echo "sku_id:$k 価格 :" . isset($coupon_detail_list[$k]) $coupon_detail_list[$k]['coupon_price'] : $v['jd_price'], "
n";

------解決策------------------
PHP コード

foreach ($arr['item_info_list'] as $key=>$val)
{
    if(isset($arr['coupon_detail_list'][$key]))
        $arr['item_info_list'][$key] = array_merge($val, $arr['coupon_detail_list'][$key]);
}

print_r($arr);
 <div class="clear"></div>
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
トラフィックの高いウェブサイトのPHPパフォーマンスチューニングトラフィックの高いウェブサイトのPHPパフォーマンスチューニングMay 14, 2025 am 12:13 AM

thesecrettokeepingaphp-poweredwebsterunningsmootlyunderheavyloadinvolvesseveralkeystrategies:1)emform opcodecoduceSciptionexecutiontime、2)aatabasequerycachingwithiThing withiThistolessendavasoload、

PHPでの依存関係注射:初心者向けのコード例PHPでの依存関係注射:初心者向けのコード例May 14, 2025 am 12:08 AM

コードをより明確かつ維持しやすくするため、依存関係が関心(DI)に注意する必要があります。 1)DIは、クラスを切り離すことにより、よりモジュール化されます。2)テストとコードの柔軟性の利便性を向上させ、3)DIコンテナを使用して複雑な依存関係を管理しますが、パフォーマンスの影響と円形の依存関係に注意してください。

PHPパフォーマンス:アプリケーションを最適化することは可能ですか?PHPパフォーマンス:アプリケーションを最適化することは可能ですか?May 14, 2025 am 12:04 AM

はい、最適化されたAphPossibleandessention.1)CachingingusapCutoredatedAtabaseload.2)最適化、効率的なQueries、およびConnectionPooling.3)EnhcodeCodewithBultinctions、Avoididingglobalbariables、およびUsingopcodeching

PHPパフォーマンスの最適化:究極のガイドPHPパフォーマンスの最適化:究極のガイドMay 14, 2025 am 12:02 AM

keyStrategIestsoSificlyvoostphpappliceperformanceare:1)useopcodecachinglikeToreexecutiontime、2)最適化abaseの相互作用とプロペラインデックス、3)3)構成

PHP依存性噴射コンテナ:クイックスタートPHP依存性噴射コンテナ:クイックスタートMay 13, 2025 am 12:11 AM

aphpDependencyInjectionContaineriSATOULTAINATINAGECLASSDEPTINCIES、強化測定性、テスト可能性、および維持可能性。

PHPの依存噴射対サービスロケーターPHPの依存噴射対サービスロケーターMay 13, 2025 am 12:10 AM

SELECT DEPENTENCINGINOFCENT(DI)大規模なアプリケーションの場合、ServicElocatorは小さなプロジェクトまたはプロトタイプに適しています。 1)DIは、コンストラクターインジェクションを通じてコードのテスト可能性とモジュール性を改善します。 2)ServiceLocatorは、センター登録を通じてサービスを取得します。これは便利ですが、コードカップリングの増加につながる可能性があります。

PHPパフォーマンス最適化戦略。PHPパフォーマンス最適化戦略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedforspeedandEfficiencyby:1)enabingopcacheinphp.ini、2)PreparedStatementswithpordatabasequeriesを使用して、3)LoopswithArray_filterandarray_mapfordataprocessing、4)の構成ngincasaSearverseproxy、5)

PHPメールの検証:電子メールが正しく送信されるようにしますPHPメールの検証:電子メールが正しく送信されるようにしますMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。