[Solved] How to construct sub arrays from a main array

You mean like this?: $array = array( array(‘id’ => 1, ‘status’ => -1), array(‘id’ => 2, ‘status’ => 1), array(‘id’ => 3, ‘status’ => 2), array(‘id’ => 4, ‘status’ => 2), array(‘id’ => 5, ‘status’ => 2) ); $statuses = array(); foreach($array as $one){ if(!isset($statuses[$one[‘status’]])){ $statuses[$one[‘status’]] = 0; } $statuses[$one[‘status’]]++; } $newArray = array(); foreach($statuses … Read more

[Solved] How can i create dynamically allocated array In C [duplicate]

Assuming you have the number of rows “r” and the number of columns “c”, you can do this: int **arr; arr = malloc(r*sizeof(int*)); for(int i=0; i < r; i++) { arr[i] = malloc(c*sizeof(int)); } this dynamically allocates an array of pointers to integers, and then allocates arrays of integers to each pointer. Don’t forget to … Read more

[Solved] Std vector of std matrices (vector of vectors) in c++

A three dimensional vector follows the same format that a 2 dimension vector has. If A, B, C … are defined as std::vector<std::vector<double> > A (6,std::vector<double>(6)); Then their type is std::vector<std::vector<double> >. To create a vector that will hold 8 of those then you need to use std::vector<std::vector<std::vector<double>>> someName(8); If you want to have the … Read more

[Solved] Convert an int** array into a char** array of a different size / composition [closed]

I think that you needed string, not 2D-Array. You can be written out to a string like write to the standard output by implementing a string that a simple extension. #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct char_vec { char *v; size_t capacity; size_t used; } sstream; sstream *ss_new(void); void ss_free(sstream *ss); void ss_putc(sstream … Read more

[Solved] create a JSON file in java with array

A little helper makes life easier: public static JSONArray jsonArray(Object… values) { JSONArray arr = new JSONArray(); arr.addAll(Arrays.asList(values)); return arr; } Then: JSONObject obj = new JSONObject(); obj.put(“data”, jsonArray(jsonArray(“1”, “YES”, “sp_1”, “1”, “xxx”), jsonArray(“2”, “NO” , “sp_2”, “2”, “yyyy”), jsonArray(“3”, “YES”, “sp_3”, “2”, “zzzz”))); System.out.println(obj.toJSONString()); Output {“data”:[[“1″,”YES”,”sp_1″,”1″,”xxx”],[“2″,”NO”,”sp_2″,”2″,”yyyy”],[“3″,”YES”,”sp_3″,”2″,”zzzz”]]} 1 solved create a JSON file in java … Read more