假设数组a:
array ( 0 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12647212', 'total' => '60', 'snp' => '15', 'mount' => '4', 'lp_no' => 'P000000D', ), 1 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12654172', 'total' => '615', 'snp' => '15', 'mount' => '41', 'lp_no' => 'P000000D', ),)
当满足整个total为一定条件时,将数组拆分开来。例中total为675,假设拆分条件为total满足225,也就是拆分为3个数组,如何能将数组拆分成这样?
//barray ( 0 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12647212', 'total' => '60', 'snp' => '15', 'mount' => '4', 'lp_no' => 'P000000D', ), 1 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12654172', 'total' => '165', 'snp' => '15', 'mount' => '11', 'lp_no' => 'P000000D', ),)//carray ( 0 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12647212', 'total' => '225', 'snp' => '15', 'mount' => '15', 'lp_no' => 'P000000D', ),)//darray ( 0 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12647212', 'total' => '225', 'snp' => '15', 'mount' => '15', 'lp_no' => 'P000000D', ),)
回复讨论(解决方案)
$a = array ( 0 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12647212', 'total' => '60', 'snp' => '15', 'mount' => '4', 'lp_no' => 'P000000D', ), 1 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12654172', 'total' => '615', 'snp' => '15', 'mount' => '41', 'lp_no' => 'P000000D', ),);$t = 225;foreach($a as $v) { $t1 = $v['total']; $v['total'] = $t1 % $t; $res[] = $v; $t1 -= $v['total']; while($t1 >= $t) { $v['total'] = $t; $t1 -= $t; $res[] = $v; }}print_r($res);Array
(
[0] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12647212
[total] => 60
[snp] => 15
[mount] => 4
[lp_no] => P000000D
)
[1] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 165
[snp] => 15
[mount] => 41
[lp_no] => P000000D
)
[2] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 225
[snp] => 15
[mount] => 41
[lp_no] => P000000D
)
[3] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 225
[snp] => 15
[mount] => 41
[lp_no] => P000000D
)
)
...
能不能变成这样?把3组区分出来。
1楼
如果mount项的值也发生改变,是不是和这个一样?
$t = 225;foreach($a as $v) { $t1 = $v['total']; $v['total'] = $t1 % $t; $res[] = $v; $t1 -= $v['total']; while($t1 >= $t) { $v['total'] = $t; $t1 -= $t; $res[] = $v; }}print_r($res);
能不能获取这样的结果?
Array([0]=>Array( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12647212 [total] => 60 [snp] => 15 [mount] => 4 [lp_no] => P000000D ) [1] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 165 [snp] => 15 [mount] => 41 [lp_no] => P000000D ))[1] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 225 [snp] => 15 [mount] => 41 [lp_no] => P000000D )[2] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 225 [snp] => 15 [mount] => 41 [lp_no] => P000000D ))
当然可以,不过有什么意义呢?
$a = array ( 0 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12647212', 'total' => '60', 'snp' => '15', 'mount' => '4', 'lp_no' => 'P000000D', ), 1 => array ( 'po_num' => 'DYNP-770266110-00', 'plant' => 'DYNP', 'get_date' => '2013-09-09', 'cust_no' => '12654172', 'total' => '615', 'snp' => '15', 'mount' => '41', 'lp_no' => 'P000000D', ),);$t = 225;$k = 0;foreach($a as $v) { $t1 = $v['total']; $v['total'] = $t1 % $t; $res[$k][] = $v; $t1 -= $v['total']; while($t1 >= $t) { $v['total'] = $t; $t1 -= $t; $res[++$k] = $v; }}print_r($res);Array
(
[0] => Array
(
[0] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12647212
[total] => 60
[snp] => 15
[mount] => 4
[lp_no] => P000000D
)
[1] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 165
[snp] => 15
[mount] => 41
[lp_no] => P000000D
)
)
[1] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 225
[snp] => 15
[mount] => 41
[lp_no] => P000000D
)
[2] => Array
(
[po_num] => DYNP-770266110-00
[plant] => DYNP
[get_date] => 2013-09-09
[cust_no] => 12654172
[total] => 225
[snp] => 15
[mount] => 41
[lp_no] => P000000D
)
)
当然可以,不过有什么意义呢?
我是想记循环输出的结果,foreach($res1 as $value)这样。
当然可以,不过有什么意义呢?
我用了array_chunk,怎么结果变成了这样?
Array( [0] => Array ( [0] => Array ( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12647212 [total] => 60 [snp] => 15 [mount] => 4 [lp_no] => P000000D ) [1] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 165 [snp] => 15 [mount] => 11 [lp_no] => P000000D ) ) ) [1] => Array ( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 225 [snp] => 15 [mount] => 15 [lp_no] => P000000D ) ) [2] => Array ( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 225 [snp] => 15 [mount] => 15 [lp_no] => P000000D ) ))
能否变成这样?
Array( [0] => Array ( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12647212 [total] => 60 [snp] => 15 [mount] => 4 [lp_no] => P000000D ) [1] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 165 [snp] => 15 [mount] => 11 [lp_no] => P000000D ) ) [1] => Array ( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 225 [snp] => 15 [mount] => 15 [lp_no] => P000000D ) ) [2] => Array ( [0] => Array ( [po_num] => DYNP-770266110-00 [plant] => DYNP [get_date] => 2013-09-09 [cust_no] => 12654172 [total] => 225 [snp] => 15 [mount] => 15 [lp_no] => P000000D ) ))
foreach($a as $v) {
$t1 = $v['total'];
$v['total'] = $t1 % $t;
$res[$k][] = $v;
$t1 -= $v['total'];
while($t1 >= $t) {
$v['total'] = $t;
$t1 -= $t;
$res[++$k] [] = $v;
}
}

phpsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIdStoredInAcookie.here'showtomanageThemeffectionaly:1)startAsessionWithSessionWwithSession_start()和stordoredAtain $ _session.2)

在PHP中,遍歷會話數據可以通過以下步驟實現:1.使用session_start()啟動會話。 2.通過foreach循環遍歷$_SESSION數組中的所有鍵值對。 3.處理複雜數據結構時,使用is_array()或is_object()函數,並用print_r()輸出詳細信息。 4.優化遍歷時,可採用分頁處理,避免一次性處理大量數據。這將幫助你在實際項目中更有效地管理和使用PHP會話數據。

會話通過服務器端的狀態管理機制實現用戶認證。 1)會話創建並生成唯一ID,2)ID通過cookies傳遞,3)服務器存儲並通過ID訪問會話數據,4)實現用戶認證和狀態管理,提升應用安全性和用戶體驗。

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

PHPSession失效的原因包括配置錯誤、Cookie問題和Session過期。 1.配置錯誤:檢查並設置正確的session.save_path。 2.Cookie問題:確保Cookie設置正確。 3.Session過期:調整session.gc_maxlifetime值以延長會話時間。

在PHP中調試會話問題的方法包括:1.檢查會話是否正確啟動;2.驗證會話ID的傳遞;3.檢查會話數據的存儲和讀取;4.查看服務器配置。通過輸出會話ID和數據、查看會話文件內容等方法,可以有效診斷和解決會話相關的問題。

多次調用session_start()會導致警告信息和可能的數據覆蓋。 1)PHP會發出警告,提示session已啟動。 2)可能導致session數據意外覆蓋。 3)使用session_status()檢查session狀態,避免重複調用。

在PHP中配置會話生命週期可以通過設置session.gc_maxlifetime和session.cookie_lifetime來實現。 1)session.gc_maxlifetime控制服務器端會話數據的存活時間,2)session.cookie_lifetime控制客戶端cookie的生命週期,設置為0時cookie在瀏覽器關閉時過期。


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

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

SublimeText3 Linux新版
SublimeText3 Linux最新版

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中