2 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以使用以下函數(shù)對(duì)數(shù)組元素進(jìn)行擬合array_filter:
$jsonStr = '{
"general_rates" : [
{ "id" : 1, "item" : "Item name", "cost1": "", "cost2": "", "cost3": "" },
{ "id" : 2, "item" : "", "cost1": "N/A", "cost2": "N/A", "cost3": 60 }
],
"value1" : "EUROPE",
"value2" : "AMERICA",
"value3" : "FRANCE"
}';
$decoded = json_decode($jsonStr, true);
// Filter the array elements which key start with 'value'
$filtered = array_filter($decoded, function ($key) {
return strpos($key, 'value') === 0;
}, ARRAY_FILTER_USE_KEY);
var_dump(count($filtered));
- 2 回答
- 0 關(guān)注
- 174 瀏覽
添加回答
舉報(bào)