array

I need a more efficient way of checking if multiple $_POST parameters isset

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have these variables, and I need to check if all of them isset(). I feel there has to be a more efficient way of checking them rather than one at a time. $jdmMethod = $_POST [ 'jdmMethod' ]; $cmdMethod = $_POST [ 'cmdMethod' ]; $vbsMethod = $_POST [ 'vbsMethod' ]; $blankPage = $_POST [ 'blankPage' ]; $facebook = $_POST [ 'facebook' ]; $tinychat = $_POST [ 'tinychat' ]; $runescape = $_POST [ 'runescape' ]; $fileUrl = escapeshellcmd ( $_POST [ 'fileUrl' ]); $redirectUrl = escapeshellcmd ( $_POST [ 'redirectUrl' ]); $fileName =

Concat first item of array to first itiem of second array JavaScript

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: how can I concat more rationally first item of array to first of second array and so on? Basically automate console.log here is the code: $("button#search").on("click", function(){ var inputVal = $("input#text").val(); $.getJSON("https://en.wikipedia.org/w/api.php?action=opensearch&search=" + inputVal +"&limit=5&namespace=0&format=json&callback=?", function(json) { var itemName = $.each(json[1], function(i, val){ }) var itemDescription = $.each(json[2], function(i, val){ }) var itemLink = $.each(json[3], function(i, val){ }) console.log

33. Search in Rotated Sorted Array

大城市里の小女人 提交于 2019-12-03 10:04:11
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2] ). You are given a target value to search. If found in the array return its index, otherwise return -1 . You may assume no duplicate exists in the array. Your algorithm's runtime complexity must be in the order of O (log n ). Example 1: Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 Example 2: Input: nums = [4,5,6,7,0,1,2], target = 3 Output: -1比较笨的办法, 既然数组被旋转了,找出在哪里旋转的就好.接着就是普通的二分查找,使用stl自带的binary_search也可以.但是本题有一个test case是 [1,3] 3 ????

Create array (collection) of buttons from existing buttons

匿名 (未验证) 提交于 2019-12-03 10:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: is there a simple way of creating a button collection from the existing buttons on my form? (In c#). I have a series of buttons already on my form and I want to use an index to access them...e.g.: myButtonArray [ 0 ]. ForeColor ... // Do something with it Can this be done? Edit: Can I set the array to have a generic OnClick event? And then determine which button in the array was clicked and, say, change its color? 回答1: You can do it the same way as for any other array. For example: Button [] array = { firstButton , secondButton };

Javascript: What's the algorithmic performance of 'splice'?

匿名 (未验证) 提交于 2019-12-03 10:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: That is, would I be better suited to use some kind of tree or skip list data structure if I need to be calling this function a lot for individual array insertions? 回答1: You might consider whether you want to use a straight map instead; all JavaScript objects (including Array instances) are maps, and so an implementation should (note I don't say "does") have a reasonable performance hashing algorithm. Aside from that, the performance of splice is going to vary a lot between implementations (e.g., vendors). This is one reason why "don't

ISO C90 forbids variable length array

匿名 (未验证) 提交于 2019-12-03 09:58:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm dynamically calculating the size of an array. Something like: void foo(size_t limit) { char buffer[limit * 14 + 1]; } But just GCC compiler says: error: ISO C90 forbids variable length array ‘buffer’ searching on SO I found this answer : C99 §6.7.5.2: If the size is an expression that is not an integer constant expression... ...each time it is evaluated it shall have a value greater than zero. So, I did the re-declaration of size limit type variable to: void foo(const size_t limit) But it continues to give warning for me. Is this a GCC

Finding the sum of a nested array

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I tried finding the sum of all numbers of a nested array, but I don't get it to work correctly. This is what I tried: function arraySum(i) { sum=0; for(a=0;a<i.length;a++){ if(typeof i[a]=="number"){ sum+=i[a]; }else if(i[a] instanceof Array){ sum+=arraySum(i[a]); } } return sum; } Does somebody know where there is a mistake in it? When you try it out with the array [[1,2,3],4,5], it gets 6 as answer, instead of 15. I don't know why. 回答1: The problem with your code is that the sum and a variables are global, instead of local. Because of this

How to remove empty values from multidimensional array in PHP?

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been looking a lot of answers, but none of them are working for me. This is the data assigned to my $quantities array: Array( [10] => Array([25.00] => 1) [9] => Array([30.00] => 3) [8] => Array([30.00] => 4) [12] => Array([35.00] => ) [1] => Array([30.00] => ) [2] => Array([30.00] => ) ) I'm looking for a way to remove the subarrays with empty values like [12] [1] and [2] while keeping everything else. The desired result: Array( [10] => Array([25.00] => 1) [9] => Array([30.00] => 3) [8] => Array([30.00] => 4) ) I tried a lot of the

Iterating over integer[] in PL/pgSQL

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to loop through an integer array ( integer[] ) in a plpgsql function. Something like this: declare a integer [] = array [ 1 , 2 , 3 ]; i bigint ; begin for i in a loop raise notice "% " , i ; end loop ; return true ; end In my actual use case the integer array a is passed as parameter to the function. I get this error: ERROR : syntax error at or near "$1" LINE 1 : $1 How to loop through the array properly? 回答1: DECLARE a integer [] := array [ 1 , 2 , 3 ]; i integer ; -- int , not bigint ! BEGIN FOR i IN 1 .. array_upper

How to pass a variable (array of strings) to other PowerShell scripts

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a variable $Tasks in a PowerShell script that contains an array of strings, and I need to pass the variable along to other PowerShell scripts and do stuff with it, like loop thru the array and do things with each item (string). However, at some point along the way my variable gets converted from an array to a string (usually when it hits script2.ps1), and I'm not able to loop thru it. What do I need to do to keep the variable as an array throughout the entire process? Here is the workflow of the variable: Script1.ps1 :