Array foreach modification - php

I have an array $testing like this :
Array (
[CUST_TYPE] =>
Array (
[0] => Family
[1] => Regular
[2] => Corporate
[3] => Premium )
[TOTAL_BALANCE] =>
Array (
[0] => 420946131.01
[1] => 41272033223.93
[2] => 38873647942.4
[3] => 10465337565.61 )
)
I need to convert (print) this array into something like this :
{
cust_type : Family,
balance : 420946131.01
},
{
cust_type : Regular ,
balance : 41272033223.93
},
and so on..
Here is simple foreach that I used, but it can only print cust_type or balance
$cols = array_keys($testing);
foreach ($testing[$cols[1]] as $i => $j) {
echo '{cust_type : ' . $j .
', balance : ' . $<What should I print??> . '},';
}
Kindly please to help.
Thank you.

Consider this snippet,
for($i=0; $i<count($your_array['CUST_TYPE']); $i++)
{
$required[] = [ 'cust_type' => $your_array['CUST_TYPE'][$i],
'balance' => $your_array['TOTAL_BALANCE'][$i] ];
}
$required = json_encode($required);
will output,
[{"cust_type":"Family","balance":420946131.01},{"cust_type":"Regular","balance":41272033223.93},{"cust_type":"Corporate","balance":38873647942.4},{"cust_type":"Premium","balance":10465337565.61}]
For other format, You can use array_combine() creates an array with first argument as keys and second as values,
The format you are specifying is json So, json_encode() will do that for you,
$required = array_combine($your_array['CUST_TYPE'], $your_array['TOTAL_BALANCE']);
$required = json_encode($required);
Now, $required is string with your desired value. Which is,
{"Family":420946131.01,"Regular":41272033223.93,"Corporate":38873647942.4,"Premium":10465337565.61}
Note: Make sure you have same number of members in both $your_array['CUST_TYPE'] and $your_array['TOTAL_BALANCE'] arrays inside your input array. Otherwise you will see a warning.

Using array_map (PHP 4 >= 4.0.6, PHP 5)
$json = json_encode(array_map(function($a,$b){ return array("cust_type"=>$a,"balance"=>$b);},$array["CUST_TYPE"],$array["TOTAL_BALANCE"]));
Test
[akshay#localhost tmp]$ cat test.php
<?php
$array = array(
"CUST_TYPE" => array(
'Family',
'Regular',
'Corporate',
'Premium'
),
"TOTAL_BALANCE" => array(
420946131.01,
41272033223.93,
38873647942.4 ,
10465337565.61
)
);
// PHP 4,5
$json = json_encode(array_map(function($a,$b){ return array("cust_type"=>$a,"balance"=>$b);},$array["CUST_TYPE"],$array["TOTAL_BALANCE"]),JSON_PRETTY_PRINT);
// Input
print_r($array);
// Output
print $json."\n";
?>
Output
[akshay#localhost tmp]$ php test.php
Array
(
[CUST_TYPE] => Array
(
[0] => Family
[1] => Regular
[2] => Corporate
[3] => Premium
)
[TOTAL_BALANCE] => Array
(
[0] => 420946131.01
[1] => 41272033223.93
[2] => 38873647942.4
[3] => 10465337565.61
)
)
[
{
"cust_type": "Family",
"balance": 420946131.01
},
{
"cust_type": "Regular",
"balance": 41272033223.93
},
{
"cust_type": "Corporate",
"balance": 38873647942.4
},
{
"cust_type": "Premium",
"balance": 10465337565.61
}
]

Related

How to add element to advanced array inside foreach loop

I am trying to add my data to my array inside my foreach loop.
I have almost done it successfully, except the array is too in-depth.
It's showing array->array->{WHAT I WANT}
When I need array->{WHAT I WANT}
Example, I'm needing it to be like:
Array
(
[home] => Array
(
[0] => Dashboard\Main#index
[1] => GET
)
[home/] => Array
(
[0] => Dashboard\Main#index
[1] => GET
)
)
When at the moment, it's showing:
Array
(
[0] => Array
(
[services/content-writing] => Array
(
[0] => Dashboard\Services#contentwriting
[1] => GET
)
)
[1] => Array
(
[services/pbn-links] => Array
(
[0] => Dashboard\Services#pbnlinks
[1] => GET
)
)
)
The code I'm currently using inside my foreach loop is:
$realArray = array();
// Services exist
if($services)
{
// Sort them into our array
foreach ($services as $service) {
$servicePageName = $service->page_name;
$serviceName = str_replace(' ', '', strtolower($service->name));
$realArrayNew = array(
"services/$servicePageName" => ["Dashboard\Services#$serviceName", 'GET']
);
array_push($realArray, $realArrayNew);
//'home' => ['Dashboard\Main#index', 'GET'],
}
}
return $realArray;
The servicePageName variable must be the key field on the realArray to get the results you want.
I'm presuming you input object array looks something like this:
[
(int) 0 => object(stdClass) {
name => 'contentwriting'
page_name => 'content-writing'
},
(int) 1 => object(stdClass) {
name => 'pbnlinks'
page_name => 'pbn-links'
}
]
If we do this:
$realArray = [];
if ($services) {
foreach ($services as $service) {
$servicePageName = $service->page_name;
$serviceName = str_replace(' ', '', strtolower($service->name));
$realArray["services/$servicePageName"] = [
0 => "Dashboard\Services#$serviceName",
1 => "GET"
];
}
}
This is what we get on realArray:
[
'services/content-writing' => [
(int) 0 => 'Dashboard\Services#contentwriting',
(int) 1 => 'GET'
],
'services/pbn-links' => [
(int) 0 => 'Dashboard\Services#pbnlinks',
(int) 1 => 'GET'
]
]
This portion of the code inserts a new subarray to your main array:
$realArrayNew = array(
"services/$servicePageName" => ["Dashboard\Services#$serviceName", 'GET']
);
array_push($realArray, $realArrayNew);
Replace it all with:
$realArray["services/$servicePageName"] = ["Dashboard\Services#$serviceName", 'GET'];
That way your top level will have service names as keys.

Use array_column in combination with preg_match

Lets suppose we have an array of arrays that needs to be converted to rows
From this:
Array
(
[subject] => Array
(
[0] => EDN:LOC:DERR
[1] => EDN:LOC:DOXX
[2] => EDN:LOC:NTTT
[3] => EDN:LOC:NAGA
)
[object] => Array
(
[0] => ABS:D01::ADFPAZ01
[1] => ABS:D01::DOXYWITX
[2] => ABS:D01::NAGBAAD2
[3] => ABS:D01::NAGGAAD2
)
[units] => Array
(
[0] => ABS:D06::UNAA
[1] => ABS:D06::UMMM
[2] => ABS:D06::UPOP
[3] => ABS:D06::UPOP
)
To this:
[0] => "'DERR' , 'ADFPAZ01' , 'UNAA'"
[1] => "'DOXX' , 'DOXYWITX' , 'UMMM'"
[2] => "'NTTT' , 'NAGBAAD2' , 'UPOP'"
[3] => "'NAGA' , 'NAGGAAD2' , 'UPOP'"
So I need the arrays to be cleaned by a pattern and compressed into lines.
I managed the compact view with the following function
$array_res = array();
for ($i=0; $i<=$totalEntries-1; $i++) {
array_push($array_res, implode("', '", array_column($array_of_arrays, $i)));
}
My regex pattern is $pattern = '([^.:]*$)'; And it collects a sequence of letters from the end of the string until it finds a colon. And I used preg_match($pattern, $string, $match) to receive the proper string into the $match variable.
However, I cannot combine the above two procedures either with array_filter or array_map inside the for loop.
EDIT: Note that there can be a subarray that contains values without a colon. In that case we have to get the value as is
[units] => Array
(
[0] => NULL
[1] => VALUE1
[2] => VALUE2
[3] => NULL
)
Rather than using a regex, this just uses array_walk() to process the extracted column and for each item it uses strrchr() with : as the last character to match (although it will include the :, so uses substr() to remove the first char)...
for ($i=0; $i<=$totalEntries-1; $i++) {
$newRow = array_column($array_of_arrays, $i);
array_walk($newRow, function (&$data) {
$data = substr(strrchr(":".$data, ":") , 1);
});
$array_res[] = "'".implode("', '", $newRow)."'";
}
The part ":".$data deals with the time when there is no : in the string, it will always ensure that it does find something to use.
Other way:
$arr = [
'subject' => [ 'EDN:LOC:DERR', 'EDN:LOC:DOXX', 'EDN:LOC:NTTT', 'EDN:LOC:NAGA' ],
'object' => [ 'ABS:D01::ADFPAZ01', 'ABS:D01::DOXYWITX', 'ABS:D01::NAGBAAD2', 'ABS:D01::NAGGAAD2' ],
'units' => [ 'ABS:D06::UNAA', 'ABS:D06::UMMM', 'ABS:D06::UPOP', 'ABS:D06::UPOP' ]
];
$res = [];
$fmt = "'%s', '%s', '%s'";
foreach ($arr['subject'] as $k => $v) {
$res[] = vsprintf($fmt, preg_replace('~^.*:~', '', array_column($arr, $k)));
}
print_r($res);
Notice: If you don't know in advance your array length, nothing forbids to build the format pattern dynamically (using str_repeat or implode).

Remove subsets from each row where the same subset is found in another row

I need to remove objects from a 3d array where the same two-property object is found in any other row.
I previously asked this similar question, but my new requirements are slightly different because I was keeping one of the encountered duplicates. Now I would like for both/all encountered duplicates to be removed.
[
[
["name" => "John", "surname" => "Smith"],
["name" => "Kate", "surname" => "Winston"]
],
[
["name" => "Kate", "surname" => "Winston"],
["name" => "Jack", "surname" => "Irving"]
],
]
Desired filtered result with same original structure:
[
[
["name" => "John", "surname" => "Smith"],
],
[
["name" => "Jack", "surname" => "Irving"]
],
]
Seems like others answers don't see their own final results and don't read desired output.
Here a little bit hard solution but it works well.
Note: the input data array must have 2 object indexes and 2 arrays of objects for comparing, otherwise, it should be fixed.
$ar = Array (
0 => [(object)["name"=>"John", "surname"=>"Smith"], (object)["name"=>"Kate", "surname"=>"Winston"]],
1 => [(object)["name"=>"Kate", "surname"=>"Winston"], (object)["name"=>"Jack", "surname"=>"Irving"]]
);
$arr = [];
$k = 0; // do `if statement` only once
foreach($ar as $num=>&$subar){
foreach($subar as $num2=>$pers){
$subar[$num2] = (array)$pers; // object to array
if (!$k) {
$keys = array_keys($subar[$num2]); // collect "name" and "surname" in an array
$k++;
}
foreach($subar[$num2] as $a=>$b){
$seq = array_search($a,$keys); // index of the current key
if (!$seq) { // 0 -> "name", 1 -> "surname"
$arr[$num][$b] = '';
} else {
$arr[$num][$subar[$num2][current($keys)]] = $b;
}
}
}
}
$diff[] = array_diff($arr[0],$arr[1]); // clear duplicates from 1-st set
$diff[] = array_diff($arr[1],$arr[0]); // clear duplicates from 2-nd set
Gives result:
Array
(
[0] => Array
(
[John] => Smith
)
[1] => Array
(
[Jack] => Irving
)
)
And after you can re-create the output array:
// creating a new array
$res = [];
foreach($diff as $num=>$ns){
foreach($ns as $name=>$surname){
foreach($keys as $ind=>$key){
if ($ind % 2 == 0){
$tmp[$key] = $name; // put name
} else {
$tmp[$key] = $surname; // put surname
}
}
$res[$num] = (object)$tmp; // array to object
}
}
Output will be:
Array
(
[0] => stdClass Object
(
[name] => John
[surname] => Smith
)
[1] => stdClass Object
(
[name] => Jack
[surname] => Irving
)
)
Demo
In case of string values in the input arrays, i.e.:
$ar = [
'[{"name":"John", "surname":"Smith"}, {"name":"Kate", "surname":"Winston"}]',
'[{"name":"Kate", "surname":"Winston"}, {"name":"Jack", "surname":"Irving"}]'
];
You need a little fix:
...
foreach($ar as $num=>&$subar){
$ar[$num] = json_decode($subar);
foreach($subar as $num2=>$pers){
...
The same output you will get.
Demo
It's easier if you don't trim away the brackets [], as you stated that you did in the comments. That way, they are proper JSON strings, which we can use in PHP.
Map (or loop) over your array, and build up a $result array, where you append all the arrays from your decoded JSON. Once you have your final $result, you have an array that looks somewhat like
Array (
[0] => Array
(
[name] => John
[surname] => Smith
)
[1] => Array
(
[name] => Kate
[surname] => Winston
)
[2] => Array
(
[name] => Kate
[surname] => Winston
)
[3] => Array
(
[name] => Jack
[surname] => Irving
)
)
We have all the values in an actual array now, but there are duplicates -- which can be removed using array_unique() with the SORT_REGULAR flag.
$array = [
'[{"name":"John", "surname":"Smith"}, {"name":"Kate", "surname":"Winston"}]',
'[{"name":"Kate", "surname":"Winston"}, {"name":"Jack", "surname":"Irving"}]'
];
$result = [];
array_map(function($v) use (&$result) {
$result = array_merge($result, json_decode($v, true));
}, $array);
print_r(array_unique($result, SORT_REGULAR));
Final output:
Array
(
[0] => Array
(
[name] => John
[surname] => Smith
)
[1] => Array
(
[name] => Kate
[surname] => Winston
)
[3] => Array
(
[name] => Jack
[surname] => Irving
)
)
Live demo at https://3v4l.org/q6pZc
$array = [
'[{"name":"John", "surname":"Smith"}, {"name":"Kate", "surname":"Winston"}]',
'[{"name":"Kate", "surname":"Winston"}, {"name":"Jack", "surname":"Irving"}]'
];
$resultArray = [];
foreach ($array as $item) {
$bufferArray = array_merge($resultArray, json_decode($item));
foreach ($bufferArray as $elements) {
$key = $elements->name . $elements->surname;
if (array_key_exists($key, $resultArray)) {
unset($resultArray[$key]);
} else {
$resultArray[$key] = $elements;
}
}
}
print_r($resultArray);
Output
Array
(
[KateWinston] => stdClass Object
(
[name] => Kate
[surname] => Winston
)
[JackIrving] => stdClass Object
(
[name] => Jack
[surname] => Irving
)
)
can rewrite this into more serious code )
To remove objects from each row where a given object exists any where in any other row, you can make iterates calls of array_udiff(). Inside the function, the first parameter should be the currently iterated row and the next/subsequent parameter(s) should all of the other rows in the entire array. The last parameter is the callback which compares whole objects to whole objects via PHP's performance-optimized algorithm.
My snippet below will not only handle your 2-row array, it will also handle arrays with 3 or more rows.
Code: (Demo)
$result = [];
foreach ($array as $i => $objs) {
$cache = $array[$i];
unset($array[$i]);
$params = [
$objs,
...$array,
fn($a, $b) => $a <=> $b
];
$result[] = array_udiff(...$params);
$array[$i] = $cache;
}
var_export($result);
To be clear, this snippet will work the same if the array of arrays of objects is an array of arrays of arrays.

Multidimensional array in PHP using foreach loop [duplicate]

This question already has answers here:
Looping a multidimensional array in php
(3 answers)
Closed last year.
Here is an array from which I need to sort out the dept name, the full name and the salary , whose salary are above 10000rs.
The array is:
Array
(
[PHP] => Array
(
[0] => Array
(
[name] => Jay
[salary] => 8000
)
[1] => Array
(
[name] => Raj
[salary] => 15000
)
[2] => Array
(
[name] => Mihir
[salary] => 12000
)
)
[Flex] => Array
(
[0] => Array
(
[name] => Vijay
[salary] => 14000
)
)
[System] => Array
(
[0] => Array
(
[name] => Kishan
[salary] => 5000
)
)
)
I am totally confused inside the loops of foreach and don't know how to call each value from the array.
My code allows me to display only names.
Can i know what is the best way to print and work with multidimensional arrays in PHP.
My code:
foreach($newArray as $x=>$x_value){
foreach ($x_value as $y=> $y_value){
if($y_value['salary']>10000)
echo $y_value['name']." has ". $y_value['salary']. ", ";
}
}
Use the following, Tested and working
$filterArray = array();
$i = 0;
foreach($salary as $dept => $employee){
foreach($employee as $index => $data){
if($data['salary'] > 10000){
$filterArray[$i]['deprtment'] = $dept;
$filterArray[$i]['name'] = $data['name'];
$filterArray[$i]['salary'] = $data['salary'];
}
$i++;
}
}
Result :-
Array
(
[1] => Array
(
[deprtment] => PHP
[name] => Raj
[salary] => 15000
)
[2] => Array
(
[deprtment] => PHP
[name] => Mihir
[salary] => 12000
)
[3] => Array
(
[deprtment] => Flex
[name] => Vijay
[salary] => 14000
)
)
Your input is nested array. So you have to use foreach +for loop:
$final_array = array();
foreach($newArray as $x=>$x_value)
{
foreach ($i=0;$i<count($x_value);$i++)
{
if($x_value[$i]['salary']>10000)
{
if(isset($final_array[$x]))
{
array_push($final_array[$x],array("name"=>$x_value[$i]['name'],"salary"=>$x_value[$i]['salary']));
}
else
{
$final_array[$x] = array();
array_push($final_array[$x],array("name"=>$x_value[$i]['name'],"salary"=>$x_value[$i]['salary']));
}
}
}
}
$final_array print dep wise name & salary which is max than 10000
Output :
Array
(
[PHP] => Array
(
[0]=> Array
(
[name] => Raj
[salary] => 15000
)
[1]=> Array
(
[name] => Mihir
[salary] => 12000
)
)
[Flex] => Array
(
[0]=> Array
(
[name] => Vijay
[salary] => 14000)
)
)
)
Here is a simpler solution for looping over the arrays.
foreach ($bigArray as $department => $employees) {
foreach ($employees as $employee) {
if ($employee["salary"] > 10000) {
echo "Department: " . $department;
echo "Employee: " . $employee;
echo "Salary: " . $salary;
} else {
echo $person . " has no money.";
}
}
}
This will output what you were trying to print in your example.
Output for the first employee:
Department: <department name>
Employee: Raj
Salary: 15000
In the future, you should include the department names in your example array since your example doesn't have all of the information you are trying to print; we can't print something that doesn't exist.
I don't know, if i've got you correctly, but if you need to filter out all the people from the sub-arrays (PHP, Flex, System, ...) and then sort them either by their name or salary, you could do it in this or a similar way:
$array = [
'PHP' => [
[
'name' => 'Jay',
'salary' => 8000
],
[
'name' => 'Raj',
'salary' => 15000
],
[
'name' => 'Mihir',
'salary' => 12000
]
],
'Flex' => [
[
'name' => 'Vijay',
'salary' => 14000
]
],
'System' => [
[
'name' => 'Kishan',
'salary' => 5000
]
]
];
$array_people = [];
$array_sorted = [];
$sort_by = 'name'; // Array key name
$sort_desc = false;
$min_salary = 10000;
foreach ($array as $type => $people)
{
foreach ($people as $info)
{
if ($info['salary'] >= $min_salary) {
$array_sorted[] = $info[$sort_by];
$array_people[] = $info;
}
}
}
if ($sort_desc) {
// Sort descending
arsort($array_sorted);
} else {
// Sort ascending
asort($array_sorted);
}
$array_final = [];
foreach (array_keys($array_sorted) as $index)
{
$array_final[] = $array_people[$index];
}
print_r($array_final);
Output:
Array
(
[0] => Array
(
[name] => Mihir
[salary] => 12000
)
[1] => Array
(
[name] => Raj
[salary] => 15000
)
[2] => Array
(
[name] => Vijay
[salary] => 14000
)
)
The first thing you need to do, is to process the main array in a way, that allows you to keep just the items you want - this items need to be stored in a different (empty) array (in this case $array_people).
While detecting the items you need, you've to get out all the values you want to sort by - this can be done at the same time. It's just about creating a new array which will contain just the values you will sort by (in this case $array_sorted).
Then comes the easier part. The next thing to do is sorting the array. There exist a bunch of functions, that can help you with this.
The functions i've used (asort and arsort) are keeping the original key of the item, so you can sort the array containing all the people by the keys of the sorted array (see the code up above).
And that's all, now you have an array with filtered and sorted people :) ... hope, this helps you.
Okay after reading so many solutions I personally believe that some of them are totally confusing for a newbie so here is the solution I actually implemented which is totally simple and easy to understand the flow of multi-dimensional array.
foreach($newArray as $x=>$x_value){
foreach ($x_value as $y=> $y_value){
if($y_value['salary']>10000){
echo "<tr>";
echo "<td>"; echo $y_value['name']; echo "</td>";
echo "<td>"; echo $x; echo "</td>";
echo "<td>"; echo $y_value['salary']; echo "</td>";
echo "</tr>";
}
}
}
The output will be like, (if u use table )

Write JSON into a file with PHP

I have this JSON-File here
{
"id" : "bf75b277-169b-49da-8ab1-b78b8dfg1b43-e25c7f28b3",
"ts" : "1372751172664",
"connected" : {
"ssid" : "eduroam",
"bssid" : "00:0f:f9:eb:08:81",
"rssi" : "-62",
"speed" : "53"
},
"configured" : [
{
"ssid" : "eduroam",
"bssid" : "null",
"keyMgmnt" : ["2", "3"],
"grCiphers" : ["0","1","2","3"]
},
{
"ssid" : "foobar",
"bssid" : "null",
"keyMgmnt" : ["0"],
"grCiphers" : ["0","1","2","3"]
}
],
"location" : {
"prov" : "network",
"lat" : "52.3793203",
"lon" : "9.7231332",
"acc" : "22.777"
}
}
and I'm trying to get the key-value-pairs out into a file (and later into a mysql-database).
I am having trouble to go along the nested structure. Maybe I do not understand it correctly?
$LOGPATH = "/var/www/test/";
$out = fopen($LOGPATH."testlog.log", "a");
$result = file_get_contents('php://input');
$data = json_decode($result, true);
$value = $data;
$test = array();
This line beneath causes me headaches, how can I say get the key-value-pairs of "connected"?
Trying $test = $data['connected'] did not work, as the output simply is a "{" and nothing more...
$test = $data;
fwrite($out, "test \n");
fwrite($out, $test);
fwrite($out, "\n");
foreach ($test as $entry){
fwrite($out, $entry);
fwrite($out, "\n");
}
Any idea how to extract the key-value-pairs and/or help me understand the structure?
This should get you on the right track
foreach($data['connected'] as $key => $value){
echo 'Key: '.$key.' Value:'.$value.'<br>';
}
json_decode() will dump JSON into regular array. You can do print_r() or var_dump() on it, to see the structure of the array. So to get your connected leaf you do:
$connected = $data['connected'];
You can then iterate over it:
foreach( $connected as $key=>$val ) {
echo $key . ": " . $val;
}
Got it, thanks to you guys!
// Get a request from i.e. a webpage (this is a webservice)
$jsonArray = file_get_contents('php://input');
// put the JSON-Data into an array
$jsonData = json_decode($jsonArray, true);
// You can simply choose the entry-points. As they do not change for me, they are hardcoded in here, else you had to use something like a for-loop to extract them
$jsonConnect = $jsonData['connected'];
$jsonLocation = $jsonData['location'];
$jsonConfigured = $jsonData['configured'];
// walk through the JSON-Data and extract the values, although the array has more than 2 levels, you can select your entry-point and walk from there on, which makes this quite easy
for($i = 0; $i < count($jsonConfigured); $i++){
// keyMgmnt itself is an array and I want to concatenate all of its values and put it into a single field in my MySQL-DB, so implode() is used
$keyMgmnt = implode(",", $jsonConfigured[$i]['keyMgmnt']);
$grCiphers = implode(",", $jsonConfigured[$i]['grCiphers']);
$ssid = $jsonConfigured[$i]['ssid'];
$bssid = $jsonConfigured[$i]['bssid'];
// from here on I simply put the variables into my MySQL-DB
$sql_configured = "INSERT INTO configured (keyMgmnt, grCiphers, ssid, bssid) VALUES ('$keyMgmnt', '$grCiphers', '$ssid', '$bssid')";
mysql_query($sql_configured) or die ("Failure in configured");
}
$sql_connected = "INSERT INTO connected (rssi, speed, ssid, bssid) VALUES ('$jsonConnect[rssi]', '$jsonConnect[speed]', '$jsonConnect[ssid]', '$jsonConnect[bssid]')";
$enterConnected = mysql_query($sql_connected) or die("Failure in connection!");
$sql_location = "INSERT INTO location (lat, prov, lon, acc) VALUES ('$jsonLocation[lat]', '$jsonLocation[prov]', '$jsonLocation[lon]', '$jsonLocation[acc]')";
$enterLocation = mysql_query($sql_location) or die("Failure in location!");
Thanks again!
Case closed.
PS: The structure of the JSON-Data. You get it by using "print_r()" or "var_dump()".
(
[id] => bf75b277-169b-49da-8ab1-b78b80f51b43-e25c7f28b3
[ts] => 1372751172664
[connected] => Array
(
[ssid] => eduroam
[bssid] => 00:0f:f7:eb:08:81
[rssi] => -62
[speed] => 54
)
[configured] => Array
(
[0] => Array
(
[ssid] => eduroam
[bssid] => null
[keyMgmnt] => Array
(
[0] => 2
[1] => 3
)
[grCiphers] => Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
)
[1] => Array
(
[ssid] => foobar
[bssid] => null
[keyMgmnt] => Array
(
[0] => 0
)
[grCiphers] => Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
)
)
[location] => Array
(
[prov] => network
[lat] => 52.3793203
[lon] => 9.7231332
[acc] => 22.777
)
)
(
[id] => bf75b277-169b-49da-8ab1-b78b80f51b43-e25c7f28b3
[ts] => 1372751172664
[connected] => Array
(
[ssid] => eduroam
[bssid] => 00:0f:f7:eb:08:81
[rssi] => -62
[speed] => 54
)
[configured] => Array
(
[0] => Array
(
[ssid] => eduroam
[bssid] => null
[keyMgmnt] => Array
(
[0] => 2
[1] => 3
)
[grCiphers] => Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
)
[1] => Array
(
[ssid] => foobar
[bssid] => null
[keyMgmnt] => Array
(
[0] => 0
)
[grCiphers] => Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
)
)
[location] => Array
(
[prov] => network
[lat] => 52.3793203
[lon] => 9.7231332
[acc] => 22.777
)
)

Categories