$t1=Array ( [0] => 1320 [1] => 990 [2] => 895 [3] => 790 [4] => 775 [5] => 745 [6] => 740 [7] => 680 [8] => 665 [9] => 535 )
$t2=Array ( [0] => 南昌 [1] => 赣州 [2] => 吉安 [3] => 九江 [4] => 南昌 [5] => 九江 [6] => 萍乡 [7] => 省外 [8] => 南昌 [9] => 九江 )
可以做一个$t11= 这个是记录值的,
$t22=这个是记录地区的。
这样子可以确保不会出现重名的情况而覆盖掉数据,但是不知道这样子能不能计算相加相同的。
$t11= Array ( [0] => 2760 [1] => 990 [2] => 895 [3] => 2070 [4] => 740 [5] => 680 )
$t22= Array ( [0] => 南昌 [1] => 赣州 [2] => 吉安 [3] => 九江 [4] => 萍乡 [5] => 省外 )
计算后的结果如上面。。就是把t2相同的去掉,同时t1里面把对于键名的相加。
回复讨论(解决方案)
先创建一个数组是 $t2数组去重后的结果(t22)
循环这个新数组(t22),对于每一个地名,去循环$t2数组. 如果这两者值(地名相同),将此时$t2对应的key 拿去$t1取值,将其加到一个新新数组($t11)的第(新数组当前循环项),并继续循环直到t22当前循环下每一个$t2的子元素都对比完毕.
继续把$t22循环完
先创建一个数组是 $t2数组去重后的结果(t22)
循环这个新数组(t22),对于每一个地名,去循环$t2数组. 如果这两者值(地名相同),将此时$t2对应的key 拿去$t1取值,将其加到一个新新数组($t11)的第(新数组当前循环项),并继续循环直到t22当前循环下每一个$t2的子元素都对比完毕.
继续把$t22循环完
请高人写代码。
$t1=Array ( 0 => 1320 ,1 => 990 ,2 => 895 ,3 => 790 ,4 => 775 ,5 => 745 ,6 => 740 ,7 => 680 ,8 => 665 ,9 => 535 );$t2=Array ( 0 => '南昌' ,1 => '赣州' ,2 => '吉安' ,3 => '九江' ,4 => '南昌' ,5 => '九江' ,6 => '萍乡' ,7 => '省外' ,8 => '南昌' ,9 => '九江' ); $t22 = array_unique($t2);$t11 = array();foreach ($t22 as $key1=>$c){ foreach($t2 as $key2=>$c2){ if($c == $c2){ $t11[$key1] += $t1[$key2]; } }}print_r($t11);print_r($t22);
Array ( [0] => 2760 [1] => 990 [2] => 895 [3] => 2070 [6] => 740 [7] => 680 )
Array ( [0] => 南昌 [1] => 赣州 [2] => 吉安 [3] => 九江 [6] => 萍乡 [7] => 省外 )
应该直接写代码 比打字说流程要快....
$t1=Array ( 0 => 1320 ,1 => 990 ,2 => 895 ,3 => 790 ,4 => 775 ,5 => 745 ,6 => 740 ,7 => 680 ,8 => 665 ,9 => 535 );$t2=Array ( 0 => '南昌' ,1 => '赣州' ,2 => '吉安' ,3 => '九江' ,4 => '南昌' ,5 => '九江' ,6 => '萍乡' ,7 => '省外' ,8 => '南昌' ,9 => '九江' ); $t22 = array_unique($t2);$t11 = array();foreach ($t22 as $key1=>$c){ foreach($t2 as $key2=>$c2){ if($c == $c2){ $t11[$key1] += $t1[$key2]; } }}print_r($t11);print_r($t22);
Array ( [0] => 2760 [1] => 990 [2] => 895 [3] => 2070 [6] => 740 [7] => 680 )
Array ( [0] => 南昌 [1] => 赣州 [2] => 吉安 [3] => 九江 [6] => 萍乡 [7] => 省外 )
应该直接写代码 比打字说流程要快....
感谢了。

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。