久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

一個(gè)更好的 php array_merge

A better php array_merge(一個(gè)更好的 php array_merge)
本文介紹了一個(gè)更好的 php array_merge的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在尋找一種更好的方法,而無需對(duì) $justPrices[$i] 的整數(shù)進(jìn)行硬編碼:

I am looking to do this a better way without the need to hardcode the integers for $justPrices[$i]:

$pricesResult = array_merge($justPrices[0], $justPrices[1], $justPrices[2], $justPrices[3]);

$justPrices 是一個(gè)多維數(shù)組,每個(gè)數(shù)組中包含 4 個(gè)價(jià)格波段".$justPrices 的數(shù)據(jù)例如:

$justPrices is a multidimensional array, containing 4 'bands' of prices within each array. The data for $justPrices being for example:

Array ( [0] => Array ( [0] => 40.95 [1] => 39.95 [2] => 39.45 [3] => 38.95 ) [1] => Array ( [0] => 45.80 [1] => 41.80 [2] => 41.50 [3] => 41.40 ) [2] => Array ( [0] => 45.95 [1] => 42.95 [2] => 41.95 [3] => 41.45 ) [3] => Array ( [0] => 50.00 [1] => 50.00 [2] => 50.00 [3] => 50.00 ) )

問題在于 $justPrices 中的數(shù)組數(shù)量至少會(huì)從 2 到 10+ 不等.所以我需要一種方法讓 array_merge() 函數(shù)的參數(shù)根據(jù) $justPrices 中的數(shù)組數(shù)量而變化.我打算使用這個(gè)簡單的方法來獲取 $justPrices 中數(shù)組的數(shù)量:

The issue is that the amount of arrays within $justPrices will vary from at least 2 to 10+. So I need a way for the parameters for the array_merge() function to vary dependent on the amount of arrays within $justPrices. I was going to use this simple method to get the amount of arrays within $justPrices:

$justPricesMax = count($justPrices);

我可以寫一個(gè) for 循環(huán),我可能仍然如此,我只是想知道是否有更好的方法來處理表面上看起來相對(duì)簡單的事情!

I could write a for loop, and I might still, I just wondered if there was a better method for what seems on the surface relatively simple!

推薦答案

如果你只是想扁平化數(shù)組,可以使用 call_user_func_array$justPrices 的元素為參數(shù)調(diào)用array_merge:

If you just want to flatten the array, you can use call_user_func_array to call array_merge with the elements of $justPrices as parameters:

$flat = call_user_func_array('array_merge', $justPrices);

這相當(dāng)于一個(gè)函數(shù)調(diào)用:

This is equivalent to a the function call:

$flat = array_merge($justPrices[0], $justPrices[1], … , $justPrices[count($justPrices)-1]);

這篇關(guān)于一個(gè)更好的 php array_merge的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動(dòng)作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個(gè)網(wǎng)站的單一入口點(diǎn).壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 久久剧场 | 先锋资源网 | 日韩在线免费视频 | 91精品国产一区二区在线观看 | 免费观看www7722午夜电影 | 精品久久一区二区三区 | 久热久热 | 亚洲精品大全 | 欧美日韩国产一区二区三区不卡 | 欧美日韩国产一区二区三区不卡 | 亚洲入口 | 国内久久精品 | 久久久久一区 | 亚洲精品久久久久久久不卡四虎 | 精品欧美一区二区三区 | 美女视频一区 | 黄色国产| 日韩在线观看中文字幕 | 人人干天天干 | 国产一级影片 | 日韩在线免费观看视频 | 久久男人 | 天天操操| 久久精品国产免费 | 欧美国产一区二区 | 精品中文字幕在线 | 久久久久久久久久久一区二区 | 精精国产xxxx视频在线野外 | www.99re5.com| 91精品国产综合久久久久久 | 毛片免费看的 | 99婷婷| 久久免费精品 | 亚洲精品美女在线观看 | 日本精品国产 | 色综合久久久 | 亚洲一区av| 欧美男人的天堂 | 一区二区伦理电影 | 日本一区二区不卡 | 国产一区二区久久久 |