multidimensional-array

merge multidimensional array with sum of values

那年仲夏 提交于 2019-12-25 08:57:43
问题 So i have an multidimensional array that looks like this: Array ( [0] => Array ( [GB] => 20827 [US] => 73 [ES] => 23 [AU] => 15 [DE] => 12 [MY] => 4 [QA] => 1 [VN] => 1 [SK] => 1 [FJ] => 1 [ME] => 1 [TR] => 1 [LV] => 1 ) [1] => Array ( [GB] => 15070 [US] => 3920 [IE] => 1711 [PH] => 1071 [MT] => 578 [AU] => 423 [HR] => 241 [ZA] => 210 [FR] => 139 ) ) I want to create a new array with all of the keys in each array of the multidimensional array along with the sum of values. This is the result i

php save data into two rows at a time in database?

白昼怎懂夜的黑 提交于 2019-12-25 08:43:17
问题 I have a form like this <form class="product-data" action=""> <table> <tr class="data-row"> <td> <input type="number" name="finance[a][source_unit]" > </td> <td > <input type="number" name="finance[a][target_unit]"> </td> <td> <input type="number" name="finance[a][client_price]"> </td> <td> <input type="number" name="finance[a][client_salary]" > </td> </tr> <tr class="data-row"> <td> <input type="number" name="finance[b][source_unit]" > </td> <td > <input type="number" name="finance[b][target

Foreach with a multidimensional array - Laravel Blade templating

梦想与她 提交于 2019-12-25 08:33:13
问题 I have the following array result set, I'm trying to loop through each of the results and just echo them out onto the page. I'm using Laravel 5.2 and the blade templating engine Collection {#240 ▼ #items: array:3 [▼ 0 => array:2 [▼ "name" => "desktop" "views" => "349" ] 1 => array:2 [▼ "name" => "mobile" "views" => "151" ] 2 => array:2 [▼ "name" => "tablet" "views" => "68" ] ] } This is what I have so far @foreach($devices as $device) $key = 0; $key++; $key < 2; {{ $device[$key] }},

PHP create_function with nested arrays

强颜欢笑 提交于 2019-12-25 08:26:01
问题 I need to use create_function because the server the application is running on has an outdated version of PHP. The issue is that the items I pass into usort are arrays and I need to sort by a value within the array: $sort_dist = create_function( '$a, $b', " if( $a['order-dir'] == 'asc' ) { return $a['distance'] > $b['distance']; } else { return $a['distance'] < $b['distance']; }" ); usort( $items, $sort_dist ); Gives an error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T

std::string Array Element Access

ε祈祈猫儿з 提交于 2019-12-25 08:19:24
问题 Despite being a Project Euler program, the following code doesn't actually concern it much. I want to add 50 100-digit numbers, and I'm assigning each digit of each number to an element in the array addends[100][50]. I'd then add up each digit/place individually, and carry over extra digits. The numbers are being read in from a text file named Input.txt , and it merely contains all the numbers. http://projecteuler.net/problem=13 I'm having trouble assigning characters to elements of a string

CakePHP Containable multidimensional array hierarchy

≯℡__Kan透↙ 提交于 2019-12-25 08:13:52
问题 If I do this: $cdata = $this->Party->find('first', array('contain' => array( 'Person' => array( 'Employee' => array( 'Volunteer'), 'Title')))); Debugger::dump($cdata, 10); I get this: array( 'Party' => array( 'id' => '9', 'save_bit' => true ), 'Person' => array( 'id' => '5', 'title_id' => '1', 'first_name' => 'bob', 'middle_name' => '', 'last_name' => 'brown', 'is_active' => false, 'date_of_birth' => '1999-07-07', 'gender' => 'M', 'party_id' => '9', 'Title' => array( 'id' => '1', 'title' =>

CakePHP Containable multidimensional array hierarchy

一世执手 提交于 2019-12-25 08:11:17
问题 If I do this: $cdata = $this->Party->find('first', array('contain' => array( 'Person' => array( 'Employee' => array( 'Volunteer'), 'Title')))); Debugger::dump($cdata, 10); I get this: array( 'Party' => array( 'id' => '9', 'save_bit' => true ), 'Person' => array( 'id' => '5', 'title_id' => '1', 'first_name' => 'bob', 'middle_name' => '', 'last_name' => 'brown', 'is_active' => false, 'date_of_birth' => '1999-07-07', 'gender' => 'M', 'party_id' => '9', 'Title' => array( 'id' => '1', 'title' =>

How to parse to string to multidimensional array (regex?)

淺唱寂寞╮ 提交于 2019-12-25 08:08:03
问题 I need to pass the data to an array by blocks, how can I make this? Do I need to use regex? My script gives me errors because I can not separate it as I wish. Does anyone have any ideas? Data: ~0 11111111 ~1 222222222 ~2 3333333333 ~end ~0 aaaaaaaaaaa ~1 bbbbbbbbbb ~2 cccccccccc ~3 ddddddddddd ~end ~0 yyyyyyyyyyy xxxxxxxx ffffffffff ~1 rrrrrrrrrrrr ~end I need it like this: Array ( [0] => Array ( [0] => 11111111 [1] => 222222222 [2] => 3333333333 ) ), [1] => Array ( [0] => aaaaaaaaaaa [1] =>

multidimensional array query mysql

坚强是说给别人听的谎言 提交于 2019-12-25 07:50:05
问题 I am working in a hotel reservation system, and the rates are per night. My database has two tables, one called stock and the other promotions. The first contain one row for day (365 days), and the last one only the days that have a percent of discount. Sometimes, some days have two or more different percent of discount. In this case 30 and 31 of january have 0.10 and 0.15. Table stock date | rate -------------------------- 2017-01-29 500 2017-01-30 500 2017-01-31 500 Table promotions date |

Finding a neighbour in a 2d array

梦想的初衷 提交于 2019-12-25 07:48:43
问题 I'm creating a depth first search program which searches through a 2d array to find the number 1 and always starts at 0. I'm having some trouble with finding the neighbours of each element in the array, I have a method (based off the pseudocode found here Finding neighbours in a two-dimensional array): private static void findNeighbour(Integer[][] maze) { int row = 0; int col = 0; int row_limit = maze.length; if(row_limit > 0){ int column_limit = maze[0].length; for(int y = Math.max(0, col-1)