Search Results

Search found 513 results on 21 pages for 'arr'.

Page 19/21 | < Previous Page | 15 16 17 18 19 20 21  | Next Page >

  • How to create such a PHP array in JavaScript?

    - by dfjhdfjhdf
    How to create such a PHP array in JavaScript? $arr = array('oneKey' => array('key1' => 'value1', 'key2' => 'value2'), 'anotherKey' => array('key1' => 'value1', 'key2' => 'value2')); EDIT: Guys, I forgot to mention that I would then need a simple way to sort those array('key1' = 'value1', 'key2' = 'value2') lexicographically by its keys. EDIT2: Actually I won't "convert" it. It's a way I explain things. I am more of a php guy.

    Read the article

  • Sorting array containing strings in objective c

    - by jakob
    Hello experts! I have an array named 'names' with strings looking like this: ["name_23_something", "name_25_something", "name_2_something"]; Now I would like to sort this array in ascending order so it looks like this: ["name_25_something", "name_23_something", "name_2_something"]; I guess that should start of with extracting the numbers since I want that the sorting is done by them: for(NSString *name in arr) { NSArray *nameSegments = [name componentsSeparatedByString:@"_"]; NSLog("number: %@", (NSString*)[nameSegments objectAtIndex:1]); } I'm thinking of creating a dictionary with the keys but I'm not sure if that is the correct objective-c way, maybe there some some methods I could use instead? Could you please me with some tips or example code how this sorting should be done in a proper way. Thank you

    Read the article

  • image with json and iphone

    - by alecnash
    Hi, I've got some images saved inside a db in a server and want to use them for my iphone. I created a php file so I can access them with json, got some questions though. I save all the text data from the db to a nsdictonary and it works fine. For the images should I use nsdata? Should I write a new php file for getting the image or is one enough because I am using an array to store my objects and then I use json_encode($arr) for json. Is it ok to store data to an array or is everything gonna crash?

    Read the article

  • can these templates be made unambiguous

    - by R Samuel Klatchko
    I'm trying to create a set of overloaded templates for arrays/pointers where one template will be used when the compiler knows the size of the array and the other template will be used when it doesn't: template <typename T, size_t SZ> void moo(T (&arr)[SZ]) { ... } template <typename T> void moo(T *ptr) { ... } The problem is that when the compiler knows the size of the array, the overloads are ambiguous and the compile fails. Is there some way to resolve the ambiguity (perhaps via SFINAE) or is this just not possible.

    Read the article

  • My object becomes NSCFArray when running on iPhone

    - by cagreen
    I'm really scratching my head on this one: I have an object (MyObject) which I instantiate, and this object has an NSArray member variable. The following simple code working in the sim: MyObject *myObj = [[MyObject alloc] init]; NSArray *arr = [myObj myMemberArray]; When I hover over myObj in XCode the tooltip reads "MyObject". Good! But when I debug it on the device (OS 3.1.3) I get: "[NSCFArray myMemberArray]: unrecognized selector sent to instance ... " When I hover over myObj, sure enough it reads "NSCFArray". Can anyone give me some pointers on where to go next with this? Thanks.

    Read the article

  • Ruby efficient way of building an array from an array of arrays

    - by randombits
    I have an array of ActiveRecord objects, each one which has its own respective errors array. I want to flatten it all out and get only the unique values into one array. So the top level array might look like: foo0 = Foo.new foo1 = Foo.new foo2 = Foo.new foo3 = Foo.new arr = [foo0, foo1, foo2, foo3] Each one of those objects could potentially have an array of errors, and I'd like to get just the unique message out of them and put them in another array, say called error_arr. How would you do it the "Ruby" way?

    Read the article

  • PHP - While loop

    - by Karl Entwistle
    print "<ul>"; foreach ($arr as $value) { echo("<li>" . $value[storeid] . " " . ($value[dvdstock] + $value[vhsstock]) . "</li>"); } print "</ul>"; Will output •2 20 •2 10 •1 20 •1 20 •1 10 I was wondering how I would adapt this loop so it outputs the total values for each &value[storeid] •1 50 •2 30 Thanks very much :)

    Read the article

  • Having an @ inside of a string - PHP

    - by Msencenb
    So I know that you use a backslash to escape most things in php however the @ symbol is an operator that suppresses error messages. I'm trying to put an email string like this inside of an array "[email protected]", however php is throwing an error. How do you escape the @ sign? EDIT: Here is the code example that was throwing the error: $arr = array(3=> "[email protected]",4=> "[email protected]"); However replacing the double quotes with single quotes fixes the error as answered below.... why is that true?

    Read the article

  • string parsing help

    - by sprugman
    I've got a string like this: #################### Section One #################### Data A Data B #################### Section Two #################### Data C Data D etc. I want to parse it into something like: $arr( 'Section One' => array('Data A', 'Data B'), 'Section Two' => array('Data C', 'Data D') ) At first I tried this: $sections = preg_split("/(\r?\n)(\r?\n)#/", $file_content); The problem is, the file isn't perfectly clean: sometimes there are different numbers of blank lines between the sections, or blank spaces between data rows. The section head pattern itself seems to be relatively consistent: #################### Section Title #################### The number of #'s is probably consistent, but I don't want to count on it. The white space on the title line is pretty random. Once I have it split into sections, I think it'll be pretty straightforward, but any help writing a killer reg ex to get it there would be appreciated. (Or if there's a better approach than reg ex...)

    Read the article

  • strange array in php

    - by tunpishuang
    here i wrote a function , it's general purpose is to get an array of the depIds under the parent root $depId. i use recursion method to get the array. public function getEmpsByDep($depId){ $query = "select * from ".SQLPREFIX."department where id_parent=".$depId; $stmt=$this->db->query($query); while(($row=$this->db->fetch_assoc($stmt))==true) { if($this->hasChildNode($row['DEPID'])) { $depId = $row['DEPID']; self::getEmpsByDep($depId); } else { $arr[]=$row['DEPID']; } } return ($arr); } while i think it should return a 1D array of the depid.but it return a strange 2D array like this: array(4) { [0]=> string(2) "11" [1]=> string(2) "12" [2]=> string(2) "13" [3]=> string(2) "14" } array(3) { [0]=> string(2) "19" [1]=> string(2) "20" [2]=> string(2) "21" } array(3) { [0]=> string(2) "15" [1]=> string(2) "16" [2]=> string(2) "17" } array(8) { [0]=> string(1) "2" [1]=> string(1) "4" [2]=> string(1) "5" [3]=> string(1) "6" [4]=> string(1) "7" [5]=> string(1) "8" [6]=> string(1) "9" [7]=> string(2) "10" } here is the table structure and data sample: $query[]="create table ".$sqltblpre."department( depId number(10) not null primary key, depName varchar2(50) not null, id_parent number(10) )"; //department(?????) $index=1; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',0)"; //1 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',0)"; //2 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',0)"; //3 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',0)"; //4 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',0)"; //5 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',0)"; //6 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'?????',0)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'????',0)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'????',0)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'????',0)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',1)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',1)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',1)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',1)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',3)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',3)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',3)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',3)"; //18 $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',18)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'???',18)"; $query[] = "INSERT INTO ".$sqltblpre."department values(".$index++.",'??',18)"; so in a word, how can i get the 1D array thought the right code of this function?

    Read the article

  • Passing 2D array with variable dimensions as function argument

    - by TheCrazyProgrammer
    I just saw the following code among the successful submissions at codechef. http://www.codechef.com/viewplaintext/1595846 I used to think that float max(int n,int arr[n][n]) {....} is not allowed in C++ (as 'n' is a variable). My CodeBlocks (on windows) with MinGW [gcc 4.4] gives compile time error. that "error: array bound is not an integer constant. Then how can be such a solution be accepted by CodeChef's judge. Is there any special flag that allows us to do that in C++??? EDIT: A link showing status as AC (accepted) : http://www.codechef.com/viewsolution/1595846

    Read the article

  • Help me write a nicer SQL query in Rails

    - by Sainath Mallidi
    Hi, I am trying to write an SQL query to update some of the attributes that are regularly pulled from source. the output will be a text file with the following fields: author, title, date, popularity I have two tables to update one is the author information and the other is popularity table. And the Author Active Record object has one popularity. Currently I'm doing it like this.\ arr.each { |x| x = x.split(" ") results = Author.find_by_sql("SELECT authors.id FROM authors, priorities WHERE authors.id=popularity.authors_id AND authors.author = x[0]") results[0].popularity.update_attribute("popularity", x[3]) I need two tables because the popularity keeps changing, and I need only the top 1000 popular ones, but I still need to keep the previously popular ones also. Is there any nicer way to do this, instead of one query for every new object. Thanks.

    Read the article

  • how to call a function in c# which return type is array.

    - by Manoj Wadhwani
    public CD[] GetCDCatalog() { XDocument docXML = XDocument.Load(Server.MapPath("mydata.xml")); var CDs = from cd in docXML.Descendants("Table") select new CD { title = cd.Element("title").Value, star = cd.Element("star").Value, endTime = cd.Element("endTime").Value, }; return CDs.ToArray<CD>(); } I am calling this function on page load ie. string[] arr = GetCDCatalog(); but this is giving Error Cannot implicitly convert type 'Calender.CD[]' to 'string[]' Please suggetst how can i call function on page load which return type is array.

    Read the article

  • JavaScript, transform object into array

    - by Šime Vidas
    I've got an object: var obj = { "Mike": 24, "Peter": 23, "Simon": 33, "Tom": 12, "Frank": 31 }; I want to create an array that holds the values of the object. The keys (key names) can be disregarded: [24, 23, 33, 12, 31] The order of the values is NOT important! One solution (obviously) would be do have a function that takes the values and puts them into an array: var arr = valuesToArray(obj); I will accept such a function as the answer. However, I would be more pleased if there would be an API function (ECMAScript, jQuery, browser-specific, ...) that could do this. Is there such a thing?

    Read the article

  • How to Create an Array from a Single Variable and Form Multiple Foreach Loops?

    - by matphoto
    I'm fairly proficient in HTML/CSS, but very new when it comes to the likes of PHP and Javascript. I've jumped headfirst into coding Wordpress shortcodes (basically php functions), and so far, through trial and error and seemingly endless browser refreshes, I've been able to figure everything out. I just hit a huge wall though, hence why I'm here. Basically, I'm trying to give an attribute a list of values like: attr="23, 95, 136, ect" The function then needs to take that attribute variable and create an array with it: $arr = array($attr); To me that seems as if it would work, but the array takes the whole list as one value instead. After doing that I want to create a foreach loop that parses each number from the list, possibly through yet another foreach loop if possible, and returns a section of code for each one, and I'm not quite sure how to pull that off either. Any feedback would be greatly appreciated.

    Read the article

  • C++ shifting bits

    - by Bobby
    I am new to shifting bits, but I am trying to debug the following snippet: if (!(strcmp(arr[i].GetValType(), "f64"))) { dem_content_buff[BytFldPos] = tmp_data; dem_content_buff[BytFldPos + 1] = tmp_data >> 8; dem_content_buff[BytFldPos + 2] = tmp_data >> 16; dem_content_buff[BytFldPos + 3] = tmp_data >> 24; dem_content_buff[BytFldPos + 4] = tmp_data >> 32; dem_content_buff[BytFldPos + 5] = tmp_data >> 40; dem_content_buff[BytFldPos + 6] = tmp_data >> 48; dem_content_buff[BytFldPos + 7] = tmp_data >> 56; } I am getting a warning saying the lines with "32" to "56" have a shift count that is too large. The "f64" in the predicate just means that the data should be 64bit data. How should this be done?

    Read the article

  • How do I convert a Python list of lists of lists into a C array by using ctypes?

    - by pc05
    As seen here How do I convert a Python list into a C array by using ctypes? this code will take a python array and transform it to a C array. import ctypes arr = (ctypes.c_int * len(pyarr))(*pyarr) Which would the way of doing the same with a list of lists or a lists of lists of lists? For example, for the following variable list3d = [[[40.0, 1.2, 6.0, 0.3], [50.0, 4.2, 0, 0]], [[40.0, 1.2, 6.0, 0.3], [50.0, 4.2, 0, 0]], [[40.0, 1.2, 6.0, 0.3], [50.0, 4.2, 0, 0]]] I have tried the following with no luck: ([[ctypes.c_double * 4] *2]*3)(*list3d) # *** TypeError: 'list' object is not callable (ctypes.c_double * 4 *2 *3)(*list3d) # *** TypeError: expected c_double_Array_4_Array_2 instance, got list Thank you! EDIT: Just to clarify, I am trying to get one object that contains the whole multidimensional array, not a list of objects. This object's reference will be an input to a C DLL that expects a 3D array.

    Read the article

  • regular expression on replace method of js not working

    - by user950146
    why this is not working var value = arr[row][col].replace(new RegExp('"', 'g'),'""'); Error : Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; Tablet PC 2.0) Timestamp: Tue, 10 Apr 2012 11:22:01 UTC Message: Object doesn't support this property or method Line: 1041 Char: 25 Code: 0 URI: http://example.com/? Message: Object doesn't support this property or method Line: 1041 Char: 25 Code: 0 URI: http://example.com/? Message: Object doesn't support this property or method Line: 1041 Char: 25 Code: 0 URI: http://example.com/? Note: : Error copied directly from debugger of IE8

    Read the article

  • Objective C memory management question with NSArray

    - by Robert
    I am loading an array with floats like this: NSArray *arr= [NSArray arrayWithObjects: [NSNumber numberWithFloat:1.9], [NSNumber numberWithFloat:1.7], [NSNumber numberWithFloat:1.6], [NSNumber numberWithFloat:1.9],nil]; Now I know this is the correct way of doing it, however I am confused by the retail counts. Each Object is created by the [NSNumber numberWithFloat:] method. This gives the object a retain count of 1 dosnt it? - otherwise the object would be reclaimed The arrayWithObjects: method sends a retain message to each object. This means each object has a retain cont of 2. When the array is de-allocated each object is released leaving them with a retain count of 1. What have I missed?

    Read the article

  • How to split this array into three's and place it in <td> using php?

    - by udaya
    Hi I have an php array of ten numbers $arr = array("first" => "1", "second" =>"2", "Third" =>"3", "Fourth" =>"4", "fifth" =>"5",, "sixth" =>"6", "seventh" =>"7", "eighth" =>"8", "ninth" =>"9","tenth"="10"); I have to place these values in a <td> by spliting the array in numbers of three such that my td contains first td contains <td>the first three values of an aray</td> second td contains <td>the next three values of an aray</td> third td contains <td>the next three values of an aray</td> if the remaining values in less than three in number it must be in the another td say now i have tenth value so my last td must contain tenth value

    Read the article

  • How to pass an anonymous array of strings to a JavaScript function?

    - by abatishchev
    I want to pass to an array of controls' IDs to a javascript script function so it will switch control's enable state. For example, in C# it would be like this: func(false, new[] { "Control1", "Control2", "Control3" }); In that function I want to find corresponding controls and disable/enable them. For one control I do this next way: <script type="text/javascript" language="javascript"> function switchControls(value, arr) { for (var n = 0; n < array.length; n++) document.getElementById(n).disabled = value; } </script> <asp:CheckBox runat="server" onclick="switchControls(this.checked, [ '<%= Control1.ClientID %>', '<%= Control2.ClientID %>' ])" Text="Take?" /> How to implement this properly? Have I to use jQuery?

    Read the article

  • PHP arrays & keys - fetching particular ones

    - by Rohan
    Hi Lets say I have an array with a structure like this: $arr= Array( array( "id"=>"a" "type">"apple"), array( "id"=>"b"), array( "id"=>"c"), array( "id"=>"c" "type"=>"banana") ); now I want to have a foreach loop which fetches all the array elements which have a key in them named "type". Something like foreach(all arrays which have type in them as $item) How would I do that? many thanks.

    Read the article

  • it's not possible to loop .click function (To create multipple buttons)

    - by user1542680
    Im Trying to create multiple buttons that each one of them doing something else. It working great outside of the "each" loop, But in the moment I'm inserting the .click function in the .each function it doesn't work... Here is the Code: $.each(data.arr, function(i, s){ html += '<div id="mybtn'+s.id+'"><button class="first">Btn1</button><button class="second">Btn2</button></div>'; var btnclass="#mybtn"+s.id+" .first"; $(btnclass).click(function(){ //do something }); }); Please Let me know what is wrong... Thank you very much!!! Eran.

    Read the article

  • How to re-open a closed file descriptor

    - by chaitu
    I have a scenario where i created pipe for communication between two child and parent. Parent writes (using write function)data to the pipe and closes the respective file descriptor. The problem is when i want to write data again to the pipe, the write function is returning error code -1. I think its because writing end has been closed in previous iteration. Then how to open the corresponding file descriptor after it has been closed once. I tried using open() function which requires path to some file as arguement. But i am not using any files in my application. I have simple file descriptors (int arr[2]). Is it possible to achieve above scenario with pipes????

    Read the article

  • Using IIS7 as a reverse proxy

    - by Jon
    My question is pretty much identical to the question listed but they did not get an answer as they ended up using Linux as the reverse proxy. http://serverfault.com/questions/55309/using-iis7-as-a-reverse-proxy I need to have IIS the main site and linux (Apache) being the proxied site(s). so I have site1.com (IIS7) site2.com (Linux Apache) they have subdomains of sub1.site1.com sub2.site1.com sub3.site2.com I want all traffic to go to site1.com and to say anything that is site2.com should be proxied to linux box on internal network, (believe ARR can do this but not sure how). I can not have it running as Apache doing the proxying as I need IIS exposed directly. any and all advice would be great. EDIT I think this might help me: <rule name="Canonical Host Name" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" negate="true" pattern="^cto\.com$" /> <add input="{HTTP_HOST}" negate="true" pattern="^antoniochagoury\.com$" /> <add input="{HTTP_HOST}" negate="true" pattern="www.antoniochagoury\.com$" /> </conditions> <action type="Redirect" url="http://www.cto20.com/{R:1}" redirectType="Permanent" /> </rule> from: http://www.cto20.com/post/Tips-Tricks-3-URL-Rewriting-Rules-Everyone-Should-Use.aspx I will have a look at this when I have access to the IIS7 box. Thanks

    Read the article

< Previous Page | 15 16 17 18 19 20 21  | Next Page >