Search the Community
Showing results for tags 'Multidimensional'.
-
Hello, I have this array print: Array ( [0] => Array ( [name] => color [value] => red ) [1] => Array ( [name] => color [value] => blue ) [2] => Array ( [name] => color [value] => green ) [3] => Array ( [name] => age [value] => 16 ) ) I want to receive this result: Array ( [color] => Array ( [name] => color [value] => red, blue, green ) [age] => Array ( [name] => age [value] => 16 ) ) it works using the following php code: foreach ($feature_names as $row) { if (!isset($result[$row["name"]])) { $result[$row["name"]]["name"] = $row["name"]; $result[$row["name"]]["value"] = $row["value"]; } else { $result[$row["name"]]["value"] .= ", " . $row["value"]; } } How ever in PHP 7.1 using the code $result[$row["name"]]["name"] = $row["name"]; generates an error. Does someone know a work around? Thanks in advance!
- 3 replies
-
- multidimensional
- array
-
(and 2 more)
Tagged with:
-
Hello, I'm currently learning JavaScript and I plan to work a lot with arrays. I store all arrays in external files and use JSON to access them. Now I wanted to read the names of all arrays that are nested in one main array to create a navigation list but I don't know how to do that. This is an example of a JSON file I use: {"MainArray":[ {"SubArray1":[{ ... }] }, {"SubArray2":[{ ... }] }, {"SubArray3":[{ ... }] } ]} How do I get the names of all SubArrays? I tried this // arr is a JSON-parsed string function myFunction(arr) { var out = ""; var i; for(i = 0; i < arr.MainArray.length; i++) { out += arr.MainArray[i].toString() + '<br>'; } document.getElementById("aso").innerHTML = out; } but it only creates a list of "[object Object]" items. Should I create another JSON file where all array names are listed instead?
-
<script>int[][] num = new int[4][5];num[1][1]={0,1,2,3,4};alert(num[1][2]);</script> This give my an error " Uncaught SyntaxError: Unexpected token ] " (shown by chrome) #for the "int[][] num = new int[4][5];" line Please help.