[Solved] How do i select a number in a matrix in c?

If you mean number in a matrix as follows (example for matrixSize == 4): 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 you can just calculate indexes from number matrixValues[number/matrixSize][number%matrixSize] EDIT: For case when your 2D arreay defined as int matrixValues[matrixSize][matrixSize]; All elements allocated in memory sequentially, … Read more

[Solved] How to use recursion to sum specific values in a multidimensional array?

Recursion doesn’t seem to be necessary for the “parent” direct values, so that can be done with a direct foreach loop. The “children” indirect values require recursion. I’ve elected to use array_walk_recursive() to access every “leaf node” in the array. This will also store the parents’ indirect values too, so I subtract those values after … Read more

[Solved] php convert mulitdimentional array

One option is to use array_reduce to group the array into an associative array and use subjectId as the key. Use array_values to convert the associative array into a simple array. $result = array_reduce($arr, function($c, $v){ if ( !isset( $c[$v[‘subjectId’]] ) ) $c[$v[‘subjectId’]] = array( ‘subjectId’=> $v[‘subjectId’], ‘subjectName’ => $v[‘subjectName’], ‘chapters’ => array() ); $c[$v[‘subjectId’]][‘chapters’][] … Read more

[Solved] In c++, what does an increment to a 2D array? Whats the function assert(0) doing? [closed]

Statement a[637][i]++ increases the value of the cell 637/i of two-dimensional array a. assert(0) simply aborts program execution at this point (since condition 0 means false, defining that the assertion is never met). Confer this SO answer for a more detailed explanation. solved In c++, what does an increment to a 2D array? Whats the … Read more

[Solved] Flattening of multidimensional table in PHP

Try this: function flatten_array($data) { $newArray = array(); foreach ($data as $key => $value) { if (is_array($value)) { $newArray[] = ‘Start’ . $key; $newArray = array_merge($newArray,flatten_array($value)); $newArray[] = ‘End’ . $key; } else { $newArray[$key] = $value; } } return $newArray; } $flat = flatten_array($data); print_r($flat); output: Array ( [one] => one [0] => Starttwo … Read more

[Solved] How to store array in table split by array_chunk in php? [closed]

You need to change your foreach to this to allow for the creation of new Model instance for each record set. foreach ($matches as $value) { $share_holder_info = new ShareHolderInfo(); $share_holder_info->trad_id = $rand_id; $share_holder_info->name = $value[0]; $share_holder_info->address = $value[1]; $share_holder_info->shares = $value[2]; $share_holder_info->save(); } You will need to change it to what ever your actual … Read more

[Solved] PHP arrays, getting to loop index information

I’m making an assumption about the true layout of your array, the following will create a $weekDays array to map an integer and a day of the week (I define the keys so you can shift them at any time): $weekDays = (1=>’Monday’, 2=>’Tuesday’, 3=>’Wednesday’, 4=>’Thursday’, 5=>’Friday’, 6=>’Saturday’, 7=>’Sunday’); // loop through each week-day in … Read more

[Solved] Multi-dimensional PHP array index

Here you go: <?php $array = array( array(1,2), array(3,4), array(5,6), array(7,8) ); function processArray(&$array) { for ($i = 0; $i < count($array); $i++) { if ($array[$i][0] > 4) { $array[$i][0] = $array[$i][0] – 3; } if ($array[$i][1] < 5) { $array[$i][1] = $array[$i][1] + 3; } } } processArray($array); print_r($array); Outputs: Array ( [0] => … Read more

[Solved] Dynamic Character Array – Stack

A working variation of my solution appears below. The reason I had to do it this way is because while I was able to dereference (**Array)[MAX_FILENAME_AND_PATHNAME_LEN] I was only able to modify the first string array in the array. The string array was initialized and filled several strings. While I could reference a string contained … Read more

[Solved] How to find the depth of an unlimited depthed array [duplicate]

Try this man function array_depth($array, $n = 0) { $max_depth = 1; foreach ($array as $value) { if (isset($value[‘subcategories’][0])) { $depth = $this -> array_depth($value[‘subcategories’]) + 1; if ($depth > $max_depth) { $max_depth = $depth; } } } return $max_depth; } 1 solved How to find the depth of an unlimited depthed array [duplicate]