久久久久久久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 示例)
主站蜘蛛池模板: 亚洲一区二区 | 国产精品久久久久久 | 亚洲精品一区国产精品 | 午夜理伦三级理论三级在线观看 | 欧美极品在线观看 | 国产中文区二幕区2012 | 一二区视频 | 精品av久久久久电影 | 国产精品亚洲精品 | 国产不卡一区 | 亚洲人成人一区二区在线观看 | 精产嫩模国品一二三区 | 福利二区 | 中文字幕黄色大片 | 久久久久久免费毛片精品 | 国产一区二区三区四区 | 亚洲伊人精品酒店 | 亚洲精品在线视频 | 在线一区二区观看 | 日韩在线| 精品国产一区二区三区久久久蜜月 | 91亚洲精品在线观看 | 国产精品久久久久aaaa | 人干人操| 日韩不卡一区二区 | 日韩精品成人免费观看视频 | 超级碰在线| 精品一区二区三区在线观看国产 | 中文字幕av网站 | 亚洲一区二区三区四区在线观看 | 国产色播av在线 | 九九热在线精品视频 | 亚洲色综合| 国产精品黄| 日韩精品极品视频在线观看免费 | 青青草视频网站 | 欧洲av在线| 久久精品青青大伊人av | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 日韩毛片 | 美美女高清毛片视频免费观看 |