Search Results

Search found 15239 results on 610 pages for 'array population'.

Page 43/610 | < Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >

  • Why does javascript's "in" operator return true when testing if 0 exists in an array that doesn't co

    - by Mariano Peterson
    For example, this returns true, and makes sense: var x = [1,2]; 1 in x; // true This returns false, and makes sense: var x = [1,2]; 3 in x; // false However this returns true, and I don't understand why: var x = [1,2]; 0 in x; You can quickly test it by putting this in your browser's address bar: javascript:var x=[1,2]; alert(0 in x); Why does the "in" operator in Javascript return true when testing if "0" exists in array, even when the array doesn't appear to contain "0"?

    Read the article

  • for loop with count from array, limit output? PHP

    - by Philip
    print '<div id="wrap">'; print "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">"; for($i=0; $i<count($news_comments); $i++) { print ' <tr> <td width="30%"><strong>'.$news_comments[$i]['comment_by'].'</strong></td> <td width="70%">'.$news_comments[$i]['comment_date'].'</td> </tr> <tr> <td></td> <td>'.$news_comments[$i]['comment'].'</td> </tr> '; } print '</table></div>'; $news_comments is a 3 diemensional array from mysqli_fetch_assoc returned from a function elsewhere, for some reason my for loop returns the total of the array sets such as [0][2] etc until it reaches the max amount from the counted $news_comments var which is a return function of LIMIT 10. my problem is if I add any text/html/icons inside the for loop it prints it in this case 11 times even though only array sets 1 and 2 have data inside them. How do I get around this? My function query is as follows: function news_comments() { require_once '../data/queries.php'; // get newsID from the url $urlID = $_GET['news_id']; // run our query for newsID information $news_comments = selectQuery('*', 'news_comments', 'WHERE news_id='.$urlID.'', 'ORDER BY comment_date', 'DESC', '10'); // requires 6 params // check query for results if(!$news_comments) { // loop error session and initiate var foreach($_SESSION['errors'] as $error=>$err) { print htmlentities($err) . 'for News Comments, be the first to leave a comment!'; } } else { print '<div id="wrap">'; print "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">"; for($i=0; $i<count($news_comments); $i++) { print ' <tr> <td width="30%"><strong>'.$news_comments[$i]['comment_by'].'</strong></td> <td width="70%">'.$news_comments[$i]['comment_date'].'</td> </tr> <tr> <td></td> <td>'.$news_comments[$i]['comment'].'</td> </tr> '; } print '</table></div>'; } }// End function Any help is greatly appreciated.

    Read the article

  • Get array's key recursively and create underscore seperated string.

    - by Nehal
    Hello Everyone, Right now i got an array which has some sort of information and i need to create a table from it. e.g. Student{ [Address]{ [StreetAddress] =>"Some Street" [StreetName] => "Some Name" } [Marks1] => 100 [Marks2] => 50 } Now I want to create database table like which contain the fields name as : Student_Address_StreetAddress Student_Address_StreetName Student_Marks1 Student_Marks2 It should be recursive so from any depth of array it can create the string in my format.

    Read the article

  • How can I access this nested array within my JSON object?

    - by Charles
    I'm using PHP to return a json_encode()'d array for use in my Javascript code. It's being returned as: {"parent1[]":["child1","child2","child2"],"parent2[]":["child1"]} By using the following code, I am able to access parent2 > child1 $.getJSON('myfile.php', function(data) { for (var key in data) { alert(data[key]); } } However, this doesn't give me access to child1, child2, child, of parent1. Alerting the key by itself shows 'parent1' but when I try to alert it's contents, I get undefined. I figured it would give me an object/array? How do I access the children of parent1? data[key][0] ?

    Read the article

  • Best way to pass a 2d array into javascript from php?

    - by 133794m3r
    Ok, what i'm trying to do here is to pass a 2d array from php to javascript in the easiest way possible. The main reason for this is because i have the array which is previously filled with data via the phpscript and doing it one by one and just "calling it as it's needed" will not work out too well since well there's more than just one row required when it's called and i'd rather not do something like for all of the elements in it as it's number is unknown until it gets said data from the database. I was going to do a while loop to write in some of the data into elements sot hat it coudl be later pulled up more easily but i cannot seem to find an easy way to do this currently. If anyone has an easy way to transfer this to javascript without having to do what i previously said.

    Read the article

  • How can I use Linq to create an array of dictionaries from XML?

    - by Duke
    Given the following XML structure: <courses> <course> <title>foo</title> <description>bar</description> </course> ... </courses> How could I create an array of dictionaries such that each dictionary contains all the element/value pairs within a course? What I have right now generates an array whose elements contain a single key/value dictionary for each element/value pair in a course: XElement x = XElement.Parse("...xml string..."); var foo = (from n in x.Elements() select n) .Elements().ToDictionary(y => y.Name, y => y.Value); Produces: [0] => {[course, foo]} [1] => {[description, bar]} What I'd like is this: [0] => {[course, foo], [description, bar]}

    Read the article

  • How to simplify my code... 2D array in Objective C...?

    - by Tattat
    self.myArray = [NSArray arrayWithObjects: [NSArray arrayWithObjects: [self d], [self generateMySecretObject],nil], [NSArray arrayWithObjects: [self generateMySecretObject], [self generateMySecretObject],nil],nil]; for (int k=0; k<[self.myArray count]; k++) { for(int s = 0; s<[[self.myArray objectAtIndex:k] count]; s++){ [[[self.myArray objectAtIndex:k] objectAtIndex:s] setAttribute:[self generateSecertAttribute]]; } } As you can see this is a simple 2*2 array, but it takes me lots of code to assign the NSArray in very first place, because I found that the NSArray can't assign the size at very beginning. Also, I want to set attribute one by one. I can't think of if my array change to 10*10. How long it could be. So, I hope you guys can give me some suggestions on shorten the code, and more readable. thz

    Read the article

  • PHP issue json_decode echo array

    - by dfdf
    <?php $string = file_get_contents("http://www.reddit.com/r/news.json"); $array = json_decode($string, true); echo $array['data'][0]['children'][0]['data'][0]['title'][0]; ?> I've got a problem- the code doesn't echo anything. I'm kinda new to json_decode, so any help is appreciated :-) Edit: As a response to a comment, here's what print_r results to: Array ( [kind] => Listing [data] => Array ( [modhash] => [children] => Array ( [0] => Array ( [kind] => t3 [data] => Array ( [domain] => syracuse.com [banned_by] => [media_embed] => Array ( ) [subreddit] => news [selftext_html] => [selftext] => [likes] => [secure_media] => [link_flair_text] => [id] => 1qdtqr [secure_media_embed] => Array ( ) [clicked] => [stickied] => [author] => cadencehz [media] => [score] => 1552 [approved_by] => [over_18] => [hidden] => [thumbnail] => [subreddit_id] => t5_2qh3l [edited] => [link_flair_css_class] => [author_flair_css_class] => [downs] => 978 [saved] => [is_self] => [permalink] => /r/news/comments/1qdtqr/thousands_defend_grocery_store_employee_with/ [name] => t3_1qdtqr [created] => 1384215998 [url] => http://www.syracuse.com/news/index.ssf/2013/11/thousands_come_to_defense_of_clay_wegmans_employee_with_aspergers_syndrome_after.html#incart_m-rpt-2 [author_flair_text] => [title] => Thousands defend grocery store employee with Asperger's syndrome after customer yells at him for being too slow [created_utc] => 1384187198 [ups] => 2530 [num_comments] => 401 [visited] => [num_reports] => [distinguished] => ) ) [1] => Array ( [kind] => t3 [data] => Array ( [domain] => bostonherald.com [banned_by] => [media_embed] => Array ( ) [subreddit] => news [selftext_html] => [selftext] => [likes] => [secure_media] => [link_flair_text] => [id] => 1qddl6 [secure_media_embed] => Array ( ) [clicked] => [stickied] => [author] => boxofrain [media] => [score] => 2086 [approved_by] => [over_18] => [hidden] => [thumbnail] => [subreddit_id] => t5_2qh3l [edited] => [link_flair_css_class] => [author_flair_css_class] => [downs] => 2556 [saved] => [is_self] => [permalink] => /r/news/comments/1qddl6/motorcycle_stolen_in_1961_found_is_recovered_and/ [name] => t3_1qddl6 [created] => 1384199801 [url] => http://bostonherald.com/news_opinion/offbeat_news/2013/11/man_glad_stolen_motorcycle_found_after_46_years [author_flair_text] => [title] => Motorcycle stolen in 1961 found is recovered and will be returned to it 73 year old owner. [created_utc] => 1384171001 [ups] => 4642 [num_comments] => 141 [visited] => [num_reports] => [distinguished] => ) ) [2] => Array ( [kind] => t3 [data] => Array ( [domain] => hosted.ap.org [banned_by] => [media_embed] => Array ( ) [subreddit] => news [selftext_html] => [selftext] => [likes] => [secure_media] => [link_flair_text] => [id] => 1qe6gp [secure_media_embed] => Array ( ) [clicked] => [stickied] => [author] => donkey-kick [media] => [score] => 415 [approved_by] => [over_18] => [hidden] => [thumbnail] => [subreddit_id] => t5_2qh3l [edited] => [link_flair_css_class] => [author_flair_css_class] => [downs] => 334 [saved] => [is_self] => [permalink] => /r/news/comments/1qe6gp/atheist_mega_churches_take_hold_in_the_us_and/ [name] => t3_1qe6gp [created] => 1384224670 [url] => http://hosted.ap.org/dynamic/stories/U/US_ATHEIST_MEGACHURCH?SITE=AP&amp;SECTION=HOME&amp;TEMPLATE=DEFAULT&amp;CTIME=2013-11-10-17-03-15 [author_flair_text] => [title] => Atheist Mega Churches take hold in the US and around the world. [created_utc] => 1384195870 [ups] => 749 [num_comments] => 368 [visited] => [num_reports] => [distinguished] => ) ) [3] => Array ( [kind] => t3 [data] => Array ( [domain] => abcnews.go.com [banned_by] => [media_embed] => Array ( ) [subreddit] => news [selftext_html] => [selftext] => [likes] => [secure_media] => [link_flair_text] => [id] => 1qdie4 [secure_media_embed] => Array ( ) [clicked] => [stickied] => [author] => Hoosier_made [media] => [score] => 984 [approved_by] => [over_18] => [hidden] => [thumbnail] => [subreddit_id] => t5_2qh3l [edited] => [link_flair_css_class] => [author_flair_css_class] => [downs] => 400 [saved] => [is_self] => [permalink] => /r/news/comments/1qdie4/abc_news_amy_robach_has_mammogram_live_on_gma/ [name] => t3_1qdie4 [created] => 1384206209 [url] => http://abcnews.go.com/blogs/health/2013/11/11/abc-news-amy-robach-reveals-breast-cancer-diagnosis/ [author_flair_text] => [title] => ABC News’ Amy Robach has mammogram live on GMA. Results Reveal Breast Cancer Diagnosis. [created_utc] => 1384177409 [ups] => 1384 [num_comments] => 130 [visited] => [num_reports] => [distinguished] => ) ) // ECT... I CUT HERE BECAUSE IT WENT ON FOR A WHILE [after] => t3_1qdinr [before] => ) ) Here's the url to the exact output, I had to trim the code to fit the character limit so maybe there's something I messed up ! :P Okay: Link goes here...

    Read the article

  • transforming flat php array into multidimensional one based on key value?

    - by PopRocks4344
    I have a flat array that I'm trying to make multidimensional. Basically, I want to find the items that have parents and create a subarray for that parent id. Right now (and this is simplified), it looks like this: Array ( [0] => stdClass Object ( [id] => 1 [parent] => 0 [name ] => Parent1 ) [1] => stdClass Object ( [id] => 7 [parent] => 1 [name] => Child1 ) [2] => stdClass Object ( [id] => 9 [parent] => 1 [name] => Child2 ) [3] => stdClass Object ( [id] => 2 [parent] => 0 [name ] => Parent2 ) [4] => stdClass Object ( [id] => 88 [parent] => 2 [name] => Childof2 ) ) I'm trying to make this: Array ( [0] => stdClass Object ( [id] => 1 [parent] => 0 [name ] => Parent1 [children] => stdClass Object ( [1] => stdClass Object ( [id] => 7 [parent] => 1 [name] => Child1 ) [2] => stdClass Object ( [id] => 9 [parent] => 1 [name] => Child2 ) ) ) [1] => stdClass Object ( [id] => 2 [parent] => 0 [name ] => Parent2 [children] => stdClass Object ( [0] => stdClass Object ( [id] => 88 [parent] => 2 [name] => Childof2 ) ) ) )

    Read the article

  • C++ How do you set an array of pointers to null in an initialiser list like way?

    - by boredjoe
    I am aware you cannot use an initialiser list for an array. However I have heard of ways that you can set an array of pointers to NULL in a way that is similar to an initialiser list. I am not certain how this is done. I have heard that a pointer is set to NULL by default, though I do not know if this is guaranteed/ in the C++ standard. I am also not sure if initialising through the new operator compared to normal allocation can make a difference too.

    Read the article

  • How do I create substrings from an array using PHP?

    - by mike
    I have an array of data that looks like this: 2008, Honda, Accord, Used, Car And I'm trying to figure a way to make a number of sub strings from each item in the array. For example, I would like to loop each item and create the following substrings: 2008 2008 Honda 2008 Accord 2008 Used 2008 Car 2008 Honda Accord 2008 Honda Used 2008 Honda Car 2008 Accord Honda 2008 Accord Used 2008 Accord Car 2008 Used Honda 2008 Used Accord 2008 Used Car 2008 Car Honda 2008 Car Accord 2008 Car Used Honda Honda 2008 Honda Accord Honda Used Honda Car Honda 2008 Accord Honda 2008 Used etc ... I need to make sure that there are no duplicates created and I need to prevent it from adding the same word twice (ex: Honda Honda OR 2008 Honda 2008 - i dont want that). Has anyone wrote anything like this or know where I can find a script that works the same way?

    Read the article

  • Flipping an image using a one dimensional array of characters.

    - by Jeff
    I have the data of an image loaded into memory as a one dimensional array. Since I'm trying to use OpenGL to draw it, and since it reads from the bottom up, I want to try and flip the elements of the array before they're sent to OpenGL. Maybe there's a way to tell OpenGL to read from the top to the bottom? Anyways, I tried using a few methods of sorting arrays and they also flip the image horizontally, which is very much like the original problem. So can I flip the data only one way?

    Read the article

  • How to initialize std::vector from C-style array?

    - by dehmann
    What is the cheapest way to initialize a std::vector from a C-style array? Example: In the following class, I have a vector, but due to outside restrictions, the data will be passed in as C-style array: class Foo { std::vector<double> w_; public: void set_data(double* w, int len){ // how to cheaply initialize the std::vector? } Obviously, I can call w_.resize() and then loop over the elements, or call std::copy(). Are there any better methods?

    Read the article

  • What is the easiest way to set the value of an entire array?

    - by Alex
    My current project requires me to fill an array based upon some other values. I know there's the shortcut: int arr[4][4] = { {0,0,0,0} , {0,0,0,0} , {0,0,0,0} , {0,0,0,0} }; But in this case, I need to fill the array after its declaration. I currently have my code formatted like this: int arr[4][4]; if(someothervariable == 1){ arr = { {1,1,1,1}, {1,2,3,4}, {2,,3,4,5}, {3,4,5,6} }; } But it won't compile. Is there a way to make use of the mentioned shortcut in my case? If not, whats the best fix available? I'd appreciate a way to set it without explicitly assigning each element? ie: arr[0][0] = ...

    Read the article

  • How do I do JavaScript Array Animation

    - by Henry
    I'm making a game but don't know how to do Array Animation with the png Array and game Surface that I made below. I'm trying to make it so that when the Right arrow key is pressed, the character animates as if it is walking to the right and when the Left arrow key is pressed it animates as if it is walking to the left (kind of like Mario). I put everything on a surface instead of the canvas. Everything is explained in the code below. I couldn't find help on this anywhere. I hope what I got below makes sense. I'm basically a beginner with JavaScript. I'll be back if more is needed: <!doctype html5> <html> <head></head> <script src="graphics.js"></script> <script src="object.js"></script> <body onkeydown ="keyDown(event)" onkeyup ="keyUp(event)" ></body> <script> //"Surface" is where I want to display my animation. It's like the HTML // canvas but it's not that. It's just the surface to where everything in the //game and the game itself will be displayed. var Surface = new Graphics(600, 400, "skyblue"); //here's the array that I want to use for animation var player = new Array("StandsRight.png", "WalksRight.png", "StandsLeft.png","WalksLeft.png" ); //Here is the X coordinate, Y coordinate, the beginning png for the animation, //and the object's name "player." I also turned the array into an object (but //I don't know if I was supposed to do that or not). var player = new Object(50, 100, 40, 115, "StandsRight.png","player"); //When doing animation I know that it requires a "loop", but I don't // know how to connect it so that it works with the arrays so that //it could animate. var loop = 0; //this actually puts "player" on screen. It makes player visible and //it is where I would like the animation to occur. Surface.drawObject(player); //this would be the key that makes "player" animation in the righward direction function keyDown(e) { if (e.keyCode == 39); } //this would be the key that makes "player" animation in the leftward direction function keyUp(e){ if (e.keyCode == 39); } //this is the Mainloop where the game will function MainLoop(); //the mainloop functionized function MainLoop(){ //this is how fast or slow I could want the entire game to go setTimeout(MainLoop, 10); } </script> </html> From here, are the "graphic.js" and the "object.js" files below. In this section is the graphics.js file. This graphics.js part below is linked to the: script src="graphics.js" html script section that I wrote above. Basically, below is a seperate file that I used for Graphics, and to run the code above, make this graphics.js code that I post below here, a separate filed called: graphics.js function Graphics(w,h,c) { document.body.innerHTML += "<table style='position:absolute;font- size:0;top:0;left:0;border-spacing:0;border- width:0;width:"+w+";height:"+h+";background-color:"+c+";' border=1><tr><td> </table>\n"; this.drawRectangle = function(x,y,w,h,c,n) { document.body.innerHTML += "<div style='position:absolute;font-size:0;left:" + x + ";top:" + y + ";width:" + w + ";height:" + h + ";background-color:" + c + ";' id='" + n + "'></div>\n"; } this.drawTexture = function(x,y,w,h,t,n) { document.body.innerHTML += "<img style='position:absolute;font-size:0;left:" + x + ";top:" + y + ";width:" + w + ";height:" + h + ";' id='" + n + "' src='" + t + "'> </img>\n"; } this.drawObject = function(o) { document.body.innerHTML += "<img style='position:absolute;font-size:0;left:" + o.X + ";top:" + o.Y + ";width:" + o.Width + ";height:" + o.Height + ";' id='" + o.Name + "' src='" + o.Sprite + "'></img>\n"; } this.moveGraphic = function(x,y,n) { document.getElementById(n).style.left = x; document.getElementById(n).style.top = y; } this.removeGraphic = function(n){ document.getElementById(n).parentNode.removeChild(document.getElementById(n)); } } Finally, is the object.js file linked to the script src="object.js"" in the html game file above the graphics.js part I just wrote. Basically, this is a separate file too, so thus, in order to run or test the html game code in the very first section I wrote, a person has to also make this code below a separate file called: object.js I hope this helps: function Object(x,y,w,h,t,n) { this.X = x; this.Y = y; this.Velocity_X = 0; this.Velocity_Y = 0; this.Previous_X = 0; this.Previous_Y = 0; this.Width = w; this.Height = h; this.Sprite = t; this.Name = n; this.Exists = true; } In all, this game is made based on a tutorial on youtube at: http://www.youtube.com/watch?v=t2kUzgFM4lY&feature=relmfu I'm just trying to learn how to add animations with it now. I hope the above helps. If not, let me know. Thanks

    Read the article

  • Rhino Mocks, AssertWasCalled with Arg Constraint on array parameter

    - by Etienne Giust
    Today, I had a hard time unit testing a function to make sure a Method with some array parameters was called. Method to be called : void AddUsersToRoles(string[] usernames, string[] roleNames);   I had previously used Arg<T>.Matches on complex types in other unit tests, but for some reason I was unable to find out how to apply the same logic with an array of strings.   It is actually quite simple to do, T really is a string[], so we use Arg<string[]>. As for the Matching part, a ToList() allows us to leverage the lambda expression.   sut.PermissionServices.AssertWasCalled(                 l => l.AddUsersToRoles(                     Arg<string[]>.Matches(a => a.ToList().First() == UserId.ToString())                     ,Arg<string[]>.Matches(a => a.ToList().First() == expectedRole1 && a.ToList()[1] == expectedRole2)                     )                     );   Of course, iw we expect an array with 2 or more values, the math would be something like : a => a.ToList()[0] == value1 && a.ToList()[1] == value2    … etc.

    Read the article

  • Foreach loop with 2d array of objects

    - by Jacob Millward
    I'm using a 2D array of objects to store data about tiles, or "blocks" in my gameworld. I initialise the array, fill it with data and then attempt to invoke the draw method of each object. foreach (Block block in blockList) { block.Draw(spriteBatch); } I end up with an exception being thrown "Object reference is not set to an instance of an object". What have I done wrong? EDIT: This is the code used to define the array Block[,] blockList; Then blockList = new Block[screenRectangle.Width, screenRectangle.Height]; // Fill with dummy data for (int x = 0; x <= screenRectangle.Width / texture.Width; x++) { for (int y = 0; y <= screenRectangle.Height / texture.Width; y++) { if (y >= screenRectangle.Height / (texture.Width*2)) { blockList[x, y] = new Block(1, new Rectangle(x * 16, y * 16, texture.Width, texture.Height), texture); } else { blockList[x, y] = new Block(0, new Rectangle(x * 16, y * 16, texture.Width, texture.Height), texture); } } }

    Read the article

  • Dropping multiple objects using an array in Actionscript?

    - by Eratosthenes
    I'm trying to get these fireBalls to drop more often, I'm not sure if I'm using Math.random correctly. Also, for some reason I'm getting a null reference because I think the fireBalls array waits for one to leave the stage before dropping another one? This is the relevant code: var sun:Sun=new Sun var fireBalls:Array=new Array() var left:Boolean; function onEnterFrame(event:Event){ if (left) { sun.x = sun.x - 15; }else{ sun.x = sun.x + 15; } if (fireBalls.length>0&&fireBalls[0].y>stage.stageHeight){ // Fireballs exit stage removeChild(fireBalls[0]); fireBalls.shift(); } for (var j:int=0; j<fireBalls.length; j++){ fireBalls[j].y=fireBalls[j].y+15; if (fireBalls[j].y>stage.stageHeight-fireBall.width/2){ } } if (Math.random()<.2){ // Fireballs shooting from Sun var fireBall:FireBall=new FireBall; fireBall.x=sun.x; addChild(fireBall); fireBalls.push(fireBall); } }

    Read the article

  • Bubble sorting my array does not sort it

    - by Trixmix
    I sort an array of chunks by doing this: for (int i =0; i<this.getQueue().size();i++) { for (int j =0; j<this.getQueue().size()-i-1;j++) { Chunk temp1 = this.getQueue().get(i); Chunk temp2 = this.getQueue().get(i+1); if (temp1 != null &&temp2 != null && temp2.getLocation().getY() < temp1.getLocation().getY()) { this.getQueue().set(i, temp2); this.getQueue().set(i+1, temp1); } } } What I want is the the chunks with the lowest Y coordinate will be at the start of the array and the ones with the bigger Y coordinate will be at the end of the array. And this is my result: 1024.0 944.0 1104.0 944.0 1104.0 ----BEFORE----- 944.0 1024.0 944.0 1104.0 1104.0 ---AFTER--- Why is this not working It seams fine. I dont want to use a comparator so dont suggest it. More info, the Y cords are floats. I got the result by for each looping on this queue and printed the Y locations.

    Read the article

  • Need help revolving a 2D array

    - by Brett
    Pretty much all I'm trying to do is revolve my 2D Array by its container. I'm using this array for a background and I seem to be having problems with it revolving. public class TileTransformer : GridConstants { public Tile[,] Tiles; ContentManager Content; public TileTransformer(ContentManager content) { Content = content; } public Tile[,] Wraping(Tile[,] tiles,Point shift) { Tiles = tiles; for (int x = shift.X; x < 0; x++)//Left shift { for (int X = 0; X < GridWidth; X++) { for (int Y = 0; Y < GridHeight; Y++) { if (X + 1 >GridWidth-1) { Tiles[0, Y].Container =tiles[X, Y].Container; } else { Tiles[X+1, Y].Container =tiles[X, Y].Container; } } } } for (int x = shift.X; x > 0; x--)//right shift { for (int X = 0; X < GridWidth; X++) { for (int Y = 0; Y< GridHeight; Y++) { if (X-1==-1) { Tiles[GridWidth-1, Y].Container =tiles[0, Y].Container; } else { Tiles[X - 1, Y].Container =tiles[X, Y].Container; } } } } for (int y = shift.Y; y > 0; y--)//shift up { for (int X = 0; X < GridWidth; X++) { for (int Y = 0; Y < GridHeight; Y++) { if (Y - 1 == -1) { Tiles[X, GridHeight-1].Container = tiles[X, Y].Container; } else { Tiles[X, Y - 1].Container = tiles[X, Y].Container; } } } } for (int y = shift.Y; y < 0; y++)//shift down { for (int X = 0; X < GridWidth; X++) { for (int Y = 0; Y < GridHeight; Y++) { if (Y + 1 == GridHeight) { Tiles[X, 0].Container = tiles[X, Y].Container; } else { Tiles[X, Y + 1].Container = tiles[X, Y].Container; } } } } return Tiles; } Now the Problems that I'm having is either when I shift up or left it seems the whole array is cleared back to the default state. Also when I'm revolving the array it appears to stretch it upon the sides of the screen that it is shifting towards.

    Read the article

  • Objective C: Create arrays from first array based on value

    - by Nic Hubbard
    I have an array of strings that are comma separated such as: Steve Jobs,12,CA Fake Name,21,CA Test Name,22,CA Bill Gates,44,WA Bill Nye,21,OR I have those values in an NSScanner object so that I can loop through the values and get each comma seperated value using objectAtIndex. So, what I would like to do, is group the array items into new arrays, based on a value, in this case, State. So, from those, I need to loop through, checking which state they are in, and push those into a new array, one array per state. CA Array: Steve Jobs,12,CA Fake Name,21,CA Test Name,22,CA WA Array: Bill Gates,44,WA OR Array: Bill Nye,21,OR So in the end, I would have 3 new arrays, one for each state. Also, if there were additional states used in the first array, those should have new arrays created also. Any help would be appreciated!

    Read the article

  • Min/Max across an array of objects

    - by graham.reeds
    It has been done to death pretty much, here on SO and around the 'Net. However I was wondering if there was a way to leverage the standard min/max functions of: Array.max = function(array) { return Math.max.apply(Math, array); }; Array.min = function(array) { return Math.min.apply(Math, array); }; So I can search across an array of objects of say: function Vector(x, y, z) { this.x = x; this.y = y; this.z = z; } var ArrayVector = [ /* lots of data */ ]; var min_x = ArrayVector.x.min(); // or var max_y = ArrayVector["y"].max(); Currently I have to loop through the array and compare the object values manually and craft each one to the particular need of the loop. A more general purpose way would be nice (if slightly slower).

    Read the article

  • KO 2.3.4 - Accessing validation array from callbacks in models

    - by kenny99
    Hi, Apologies if this is an oversight or sheer stupidity on my part but I can't quite figure out how to access the validation array from a callback in a model (using ORM and KO 2.3.4). I want to be able to add specific error messages to the validation array if a callback returns false. e.g This register method: public function register(array & $array, $save = FALSE) { // Initialise the validation library and setup some rules $array = Validation::factory($array) ->pre_filter('trim') ->add_rules('email', 'required', 'valid::email', array($this, 'email_available')) ->add_rules('confirm_email', 'matches[email]') ->add_rules('password', 'required', 'length[5,42]') ->add_rules('confirm_password', 'matches[password]'); return ORM::validate($array, $save); } Callback: public function email_available($value) { return ! (bool) $this->db ->where('email', $value) ->count_records($this->table_name); } I can obviously access the current model from the callback, but I was wondering what the best way to add custom error from the callback would be?

    Read the article

  • Get node content from xml file and transform it into php array?

    - by Kirzilla
    Hello, I'm looking for solution to extract some node from large xml file (using xmlstarlet http://xmlstar.sourceforge.net/) and then parse this node to php array. elements.xml <?xml version="1.0"?> <elements> <element id="1" par1="val1_1" par2="val1_2" par3="val1_3"> <title>element 1 title</title> <description>element 1 description</description> </element> <element id="2" par1="val2_1" par2="val2_2" par3="val2_3"> <title>element 2 title</title> <description>element 2 description</description> </element> </elements> To extract element tag with id="1" using xmlstarlet I'm executing this shell command... xmlstarlet sel -t -c "/elements/element[id=1]" elements.xml This shell command outputs something like this... <element id="1" par1="val1_1" par2="val1_2" par3="val1_3"> <title>element 1 title</title> <description>element 1 description</description> </element> How could I parse this shell output into php array? Thank you.

    Read the article

  • PHP foreach loop through multidimensional array

    - by Muiter
    I have an multidimensional array, how can I use it? I want to use each seperate array in an for loop. I have this code <?php foreach ($calculatie_id[$i] as $value) { echo $value; } ? print_r($calculatie_id); gives Array ( [0] = Array ( [0] = 4 [1] = 6 ) [1] = Array ( [0] = 1 [1] = 5 ) [2] = Array ( [0] = 5 [1] = 6 ) [3] = ) But when using the foreach I only get 46

    Read the article

< Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >