S
S
Shige2016-06-17 08:21:13
PHP
Shige, 2016-06-17 08:21:13

PhP nested array how to pass parameter?

Hello everyone, just a quick question. There is the following code:

$data_dst_1 =json_decode($json, true);
$data_dst_2 =json_decode($json2, true);

foreach ($data_dst_1 as $sept_1) { $DataArray_1[] = array("Rx" => $sept_1["Rx"],"sesTxBytes" => $sept_1["Tx"]); }
foreach ($data_dst_2 as $sept_2) { $DataArray_2[] = array("Rx" => $sept_2["Rx"],"sesTxBytes" => $sept_2["Tx"]); }

data_dst_1 and data_dst_2 are also an array.
How can I subtract the DataArray_1[] array from the 2nd DataArray_2[] array. The difficulty is that the array has the form of nesting, that is, $DataArray_2[] and DataArray_1[] are arrays that dynamically get another array that is decoded from JSON.
The function array_map('function',$DataArray_1,$DataArray_2);complains if DataArray_1[] and DataArray_2[] are being passed both simultaneously and one at a time. And if I omit the brackets in the code:
foreach ($data_dst_1 as $sept_1) { $DataArray_1 = array("Rx" => $sept_1["Rx"],"sesTxBytes" => $sept_1["Tx"]); }
foreach ($data_dst_2 as $sept_2) { $DataArray_2 = array("Rx" => $sept_2["Rx"],"sesTxBytes" => $sept_2["Tx"]); }
Everything is running successfully. But this is not necessary, because only the first line of the array is displayed. Given that the array accepts other dynamic arrays, this can be from 1 to several thousand. I can't figure out what the problem is.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lumore, 2016-06-17
@Lumore

$DataArray_1[][0] ?

X
xmoonlight, 2016-06-20
@xmoonlight

you need to create a function/class of operations with a tree-like associative array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question