Search Results

Search found 15172 results on 607 pages for 'array intersect'.

Page 7/607 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Remove values from array on foreach PHP

    - by user104531
    I have an array like this: Array ( [0] => Array ( [id] => 68 [type] => onetype [type_id] => 131 [name] => name1 ) [1] => Array ( [id] => 32 [type] => anothertype [type_id] => 101 [name] => name2 ) ) I need to remove some arrays from it if the users has permissions or not to see that kind of type. I am thinking on doing it with a for each, and do the needed ifs inside it to remove or let it as it. My question is: What's the most efficent way to do this? The array will have no more than 100 records. But several users will request it and do the filtering over and over.

    Read the article

  • A Simple PHP Array Manipulation

    - by Ygam
    Hi guys! how would you turn this array: array( 0 => Title1, 1 => Title2, 3 => Address1, 4 => Address2, ) to this array: array ( 0 => array( 'title' => 'Title1' 'address' =>'Address1' ), 1 => array( 'title' => 'Title2', 'address' => 'Address2' ) ); when you were initially given $_POST['title'] = array('Title1', 'Title2); $_POST['address'] = array('Address1', 'Address2'); which when merged would give you the first array I have given I was able to solve this via a high level Arr:Rotate function in Kohana framework, along with Arr::merge function but I can't quite understand the implementation. Please help

    Read the article

  • Ruby - Subclassing array to make it randomize when flattened

    - by Markus O'Reilly
    I'm trying to subclass Array in ruby to make it randomize its elements when flatten! is called. Looking at the source code for Array#flatten (http://ruby-doc.org/core/classes/Array.src/M002218.html), it looks like it should recursively call flatten! on any array contained within an array. So, I tried doing something like this: class RandArray < Array def randomize! self.sort!{rand(3)-1} end def flatten! randomize! super end end However, when a normal array contains my RandArray and flatten is called on the normal array, flatten! is never called in my array. I figure ruby is just calling some other method to flatten the arrays recursively, but I can't figure out what that is. Any tips?

    Read the article

  • generic function for extracting values from an array with one particular key in PHP

    - by Sabya
    Is it possible in PHP to extract values from an array with a particular key path and return an array of those values? I'll explain with an example: $user = array ( array( id => 1, email =>'[email protected]', project => array ('project_id' => 222, 'project_name' => 'design') ), array( id => 2, email =>'[email protected]', project => array ('project_id' => 333, 'project_name' => 'design') ) ); /** I have to write a function something like: */ $projectIds = extractValuesWithKey($user, array('project', 'project_id')); print_r($projectIds); Output: Array( [0] => 222, [1] => 333 )

    Read the article

  • Fatal error: Cannot use string offset as an array

    - by learner
    Array ( [0] = Array ( [auth_id] = 1 [auth_section] = Client Data Base [auth_parent_id] = 0 [auth_admin] = 1 [sub] = Array ( [0] = Array ( [auth_id] = 2 [auth_section] = Client Contact [auth_parent_id] = 1 [auth_admin] = 1 ) ) ) [1] => Array ( [auth_id] => 6 [auth_section] => All Back Grounds [auth_parent_id] => 0 [auth_admin] => ,4 [sub] => Array ( [0] => Array ( [auth_id] => 7 [auth_section] => Edit Custom [auth_parent_id] => 6 [auth_admin] => 1 ) ) ) [2] => Array ( [auth_id] => 20 [auth_section] => Order Mail [auth_parent_id] => 0 [auth_admin] => 1 [sub] => ) } When I process the sub inner array it shows this error how can I avoid that :)

    Read the article

  • Ruby: how to know depth of multidemensional array

    - by hqt
    This is my problem I have met in my assignment. Array A has two elements: array B and array C. Array B has two elements: array D and array E At some point, array X just contains two elements: string a and string b. I don't know how to determine how deep array A is. For example: arrA = [ [ [1,2] ] ] I have tested by: A[0][0][0] == nil which returns false. Moreover, A[0][0]..[0] == nil always returns false. So, I cannot do this way to know how deep array A is.

    Read the article

  • php multidimensional array if loop

    - by user1091558
    I have a multidimensional array like this array[value][1][1] Now i would like to implement if loop like this if ($value = array[value][1][1]) { echo "It works"; } Now it works if i assign the values like [1][1],[2][1]. Is it possible to compare the whole array. I mean if the array looks like array[value][1][1],array[value][2][1],..........,array[value][n][1] It works should be echoed. I tried like this. if ($value = array[value][][]) { echo "It works"; } But its not working. Can anyone give me the correct syntax?

    Read the article

  • Finding rows that intersect with a date period

    - by DavidWimbush
    This one is mainly a personal reminder but I hope it helps somebody else too. Let's say you have a table that covers something like currency exchange rates with columns for the start and end dates of the period each rate was applicable. Now you need to list the rates that applied during the year 2009. For some reason this always fazes me and I have to work it out with a diagram. So here's the recipe so I never have to do that again: select  * from    ExchangeRate where   StartDate < '31-DEC-2009'         and EndDate > '01-JAN-2009'   That is all!

    Read the article

  • XNA C# Rectangle Intersect Ball on a Square

    - by user2436057
    I made a Game like Peggle Deluxe using C# and XNA for lerning. I have 2 rectangles a ball and a square field. The ball gets shoot out with a cannon and if the Ball hits the Square the Square disapears and the Ball flys away.But the Ball doesent spring of realistically, it sometimes flys away in a different direction or gets stuck on the edge. Thads my Code at the moment: public void Update(Ball b, Deadline dl) { ArrayList listToDelete = new ArrayList(); foreach (Field aField in allFields) { if (aField.square.Intersects(b.ballhere)) { listToDelete.Add(aField); Punkte = Punkte + 100; float distanceX = Math.Abs(b.ballhere.X - aField.square.X); float distanceY = Math.Abs(b.ballhere.Y - aField.square.Y); if (distanceX < distanceY) { b.myMovement.X = -b.myMovement.X; } else { b.myMovement.Y = -b.myMovement.Y; } } } It changes the X or Y axis depending on how the ball hits the Square but not everytimes. What could cause the problem? Thanks for your answer. Greetings from Switzerland.

    Read the article

  • Trouble using Ray.Intersect method on bounding boxes in a 2D XNA game

    - by getsauce
    I am trying to use a ray and bounding box to determine if a box is between the player and the mouse pointer in 2D space. When I try testing the code, the collision will return true when pointed at the box but it also returns true under other circumstances where it shouldn't. For instance. If I have a player on the left and a box directly to the right, I can put the mouse pointer a few hundred pixels above the box or a few hundred below and it will still return true. Also, I can put my mouse pointer to the left of the player and in a certain area it will still return true. Does anyone have any idea what might cause this? I have left out definitions for some of my members and properties just to make this code sample easier to read. The position property is just a Vector2 for where each object is located. ray = new Ray(new Vector3(player.Position, 0), new Vector3(mouse.Position, 0); box = new BoundingBox(new Vector3(box.Position, 0), new Vector3( new Vector2(box.Position + box.Width, box.Position + box.Height), 0); if (ray.Intersects(box) != null) collision = true; else collision = false;

    Read the article

  • Dates that intersect

    - by MikeAbyss
    Hi everyone, I've been researching this problem for awhile now and I can't seem to come to a solution, hopefully someone here can help. Currently I'm working with Microsoft SQL server management, I've been trying to do the following: Previously, the old query would just return the results that fit between two dates Heres the previous query: SELECT e.Name, o.StartDate, o.EndDate FROM dbo.Name e, dbo.Date o WHERE where e.Name = o.Name and o.StartDate <= '2010-09-28 23:59:59' and o.EndDate >= '2010-9-28 00:00:00' and e.Name like 'A' Example table that is produced after the query runs (The real table has a lot more rows obviously :P) : Name Start End A 2010-09-28 07:00:00 2010-09-28 17:00:00 A 2010-09-28 13:45:00 2010-09-28 18:00:00 A 2010-09-28 08:00:00 2010-09-28 16:00:00 A 2010-09-28 07:00:00 2010-09-28 15:30:00 However we need to change this, so that the query does the following: find the dates that intersect for a day x find the dates that don't intersect for a day x I've found a real useful site regarding this http://bloggingabout.net/blogs/egiardina/archive/2008/01/30/check-intersection-of-two-date-ranges-in-sql.aspx However the date to compare against is inputted, mine on the other hand has to all dates that intersect/don't intersect. Thanks for the help everyone.

    Read the article

  • dynamically build Intersect statement ASP.NET

    - by TDDG
    I would like to use the IEnumerable function Intersect() to combine a few list and get the similar integers from each list. The problem I'm faced with is that I don't know how many list I will need to compare. Here is an example: A{1,2,3,4} B{1,2,3} C{1,2} results = A.Intersect(B).Intersect(C) This works great, but the next time around I may have a D{1,2} next time I come across the function. I'd like to use the Intersect method, but I'm open to new ideas as well.

    Read the article

  • PHP 5.2 Function needed for GENERIC sorting of a recordset array

    - by donbriggs
    Somebody must have come up with a solution for this by now. We are using PHP 5.2. (Don't ask me why.) I wrote a PHP class to display a recordset as an HTML table/datagrid, and I wish to expand it so that we can sort the datagrid by whichever column the user selects. In the below example data, we may need to sort the recordset array by Name, Shirt, Assign, or Age fields. I will take care of the display part, I just need help with sorting the data array. As usual, I query a database to get a result, iterate throught he result, and put the records into an assciateiave array. So, we end up with an array of arrays. (See below.) I need to be able to sort by any column in the dataset. However, I will not know the column names at design time, nor will I know if the colums will be string or numeric values. I have seen a ton of solutions to this, but I have not seen a GOOD and GENERIC solution Can somebody please suggest a way that I can sort the recordset array that is GENERIC, and will work on any recordset? Again, I will not know the fields names or datatypes at design time. The array presented below is ONLY an example. UPDATE: Yes, I would love to have the database do the sorting, but that is just not going to happen. The queries that we are running are very complex. (I am not really querying a table of Star Trek characters.) They include joins, limits, and complex WHERE clauses. Writing a function to pick apart the SQL statement to add an ORDER BY is really not an option. Besides, sometimes we already have the array that is a result of the query, rather than the ability to run a new query. Array ( [0] => Array ( [name] => Kirk [shrit] => Gold [assign] => Bridge ) [1] => Array ( [name] => Spock [shrit] => Blue [assign] => Bridge ) [2] => Array ( [name] => Uhura [shrit] => Red [assign] => Bridge ) [3] => Array ( [name] => Scotty [shrit] => Red [assign] => Engineering ) [4] => Array ( [name] => McCoy [shrit] => Blue [assign] => Sick Bay ) )

    Read the article

  • PHP array help getting a value from the key

    - by sea_1987
    I have a variable that looks likes this, $rslt['expected_salary_level'] This returns a string similar to LEVEL_3, in another array that looks like this I have a set of salaries, Array ( [LEVEL_1] => Array ( [nice_name] => under &pound;10,000 [low] => 1 [high] => 10000 ) [LEVEL_2] => Array ( [nice_name] => &pound;10,000 - &pound;15,000 [low] => 10000 [high] => 15000 ) [LEVEL_3] => Array ( [nice_name] => &pound;15,000 - &pound;20,000 [low] => 15000 [high] => 20000 ) [LEVEL_4] => Array ( [nice_name] => &pound;20,000 - &pound;25,000 [low] => 20000 [high] => 25000 ) [LEVEL_5] => Array ( [nice_name] => &pound;25,000 - &pound;30,000 [low] => 25000 [high] => 30000 ) [LEVEL_6] => Array ( [nice_name] => &pound;30,000 - &pound;40,000 [low] => 30000 [high] => 40000 ) [LEVEL_7] => Array ( [nice_name] => &pound;40,000 - &pound;50,000 [low] => 40000 [high] => 50000 ) [LEVEL_8] => Array ( [nice_name] => &pound;50,000 - &pound;100,000 [low] => 50000 [high] => 100000 ) [LEVEL_9] => Array ( [nice_name] => &pound;100,000 or more [low] => 100000 [high] => 9999999 ) [LEVEL_VOLUNTARY] => Array ( [nice_name] => Voluntary [low] => [high] => ) [LEVEL_UNSPECIFIED] => Array ( [nice_name] => Not specified [low] => [high] => ) ) How do I get at the associated nice name?

    Read the article

  • copy array from one class to another class array

    - by shishir.bobby
    hi all, i hv an array ("array A", which contains 3 objects, fox ex, to,from,message) in class "A". and in class "B",i m having another array ("array B"),which fills tableview,of class "B" only. i need to fill tableview,with the values of class A's array (i.e array A,with the object values, to,from,message). how can i do it?? how to copy array from another class ? i hope i m clear with my question regards shishir

    Read the article

  • How to sort an array by some specific key?

    - by vinothkumar
    I have an array look like below. $array[0]['keyword'] = 'cricket '; $array[0]['noofhits'] = '26'; $array[0]['keyword'] = 'food '; $array[0]['noofhits'] = '17'; $array[0]['keyword'] = 'mypax'; $array[0]['noofhits'] = '22'; $array[0]['keyword'] = 'next'; $array[0]['noofhits'] = '22'; $array[0]['keyword'] = 'nextbutton'; $array[0]['noofhits'] = '22'; $array[0]['keyword'] = 'picture'; $array[0]['noofhits'] = '18'; I want to sort the array using the noofhits. How can I do? Advance Thanks for your advice.

    Read the article

  • php array_unique

    - by dotty
    HAy, i have an array Array( [0] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) [1] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) [2] => Array ( [0] => 33 [user_id] => 33 [1] => 8 [frame_id] => 8 ) [3] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) [4] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) ) As you can see key 0 is the same as 1,3 and 4. And key 2 is different from them all. When running the array_unique function on them, the only left is Array ( [0] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) ) any ideas why array_unique isn't working as expected?

    Read the article

  • Scala Array constructor?

    - by Lukasz Lew
    scala> val a = Array [Double] (10) a: Array[Double] = Array(10.0) scala> val a = new Array [Double] (10) a: Array[Double] = Array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) Why these two expressions have different semantics?

    Read the article

  • PHP 2D Array output all combinations

    - by stukerr
    Hi there, I've had this problem bending my mind for a while now (head cold doesn't help either!), basically I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1] = 'pears'; $array[0][2] = 'oranges'; $array[1][0] = 'steve'; $array[1][1] = 'bob'; And I would like to be able to produce from this a table with every possible combination of these, but without repeating any combinations (regardless of their position), so for example this would output Array 0 Array 1 apples steve apples bob pears steve pears bob But I would like for this to be able to work with as many different arrays as possible. Many thanks!

    Read the article

  • adding array values

    - by christian
    Array ( [0] => Array ( [datas] => Array ( [name] => lorem [id] => 1 [type] => t1 [due_type] => Q1 [t1] => 1 [t2] => 1 [t3] => 1 ) ) [1] => Array ( [datas] => Array ( [name] => lorem [id] => 1 [type] => t2 [due_type] => Q1 [t1] => 0 [t2] => 1 [t3] => 0 ) ) [2] => Array ( [datas] => Array ( [name] => name [id] => 2 [type] => t1 [due_type] => Q1 [t1] => 1 [t2] => 0 [t3] => 1 ) ) [3] => Array ( [datas] => Array ( [name] => name [id] => 2 [type] => t2 [due_type] => Q1 [t1] => 1 [t2] => 0 [t3] => 0 ) ) ) I want to add the values of each array according to its id, but I am having problem getting the values using these code: I want to compute the sum of all type according to each due_type and combining them into one array. $totals = array(); $i = -1; foreach($datas as $key => $row){ $i += 1; $items[$i] = $row; if (isset($totals[$items[$i]['datas']['id']])){ if($totals[$items[$i]['datas']['id']]['due_type'] == 'Q1'){ if($totals[$items[$i]['datas']['id']]['type'] == 't1'){ $t1+=$totals[$items[$i]['datas']['id']]['t1']; }elseif($totals[$items[$i]['datas']['id']]['type'] == 't2'){ $t2+=$totals[$items[$i]['datas']['id']]['t2']; }elseif($totals[$items[$i]['datas']['id']]['type'] == 't3'){ $t3+=$totals[$items[$i]['datas']['id']]['t3']; } $totals[$items[$i]['datas']['id']]['t1_total'] = $t1; $totals[$items[$i]['datas']['id']]['t2_total'] = $t2; } } else { $totals[$items[$i]['datas']['id']] = $row['datas']; $totals[$items[$i]['datas']['id']]['t1_total'] = $items[$i]['datas']['t1']; $totals[$items[$i]['datas']['id']]['t2_total'] = $items[$i]['datas']['t2']; } }

    Read the article

  • PHP compare two dimension array

    - by Jerry
    Hello guys I would like to know how to compare two two-dimension arrays value. First array Array 1 ( [0] => Array ( [0] => a ) [1] => Array ( [0] => b ) [2] => Array ( [0] => c ) } Second one Array 2 ( [0] => Array ( [0] => a ) [1] => Array ( [0] => d ) [2] => Array ( [0] => e ) } I need to know if my loop could compare the arrays to check the matched value. In my case, array1[0][0]=a matches array2[0][0]=a. If it matches, php will output some html. My foreach loop foreach ($array1 as $arrays){ foreach($arrays as $array){ //need to compare array2 here not sure how to do it. } } I would appreciate any helps. Thanks!

    Read the article

  • php - arrange array to display in score order

    - by Phil Jackson
    hi, i have wrote a script to produce an array of data but now want to display in order of score. The array outputs as follows; [display_name] => Array ( [0] => ACT_Web_Designs [1] => user1_design [2] => user2_design ) [proffesion] => Array ( [0] => Web Developer [1] => web developer [2] => Web Developer ) [score] => Array ( [0] => 15 [1] => 6 [2] => 15 ) [img] => Array ( [0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic [1] => [2] => ) so in a nutshell I am wanting it to be converted as follows; [display_name] => Array ( [0] => ACT_Web_Designs [1] => user2_design [2] => user1_design ) [proffesion] => Array ( [0] => Web Developer [1] => web developer [2] => Web Developer ) [score] => Array ( [0] => 15 [1] => 15 [2] => 6 ) [img] => Array ( [0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic [1] => [2] => ) I have been looking at asort() but cant get anything to work. any help would be much appreciated.

    Read the article

  • In C, as free() knows an array size, why isn't there a function that gets the array size? [closed]

    - by user354959
    Possible Duplicate: If free() knows the length of my array, why can’t I ask for it in my own code? Searching around (including here at stackoverflow), I got that malloc() allocates an array and also creates a header to control the array info. In this header, there's also the array size. free() use such information to know how to deallocate that array. So, if the array size info is "there" (somewhere in the memory), why there isn't a function that returns an array size, looking for this at the array header? Or am I missing something?

    Read the article

  • Get index values for an array to print in value attribute for radio buttons

    - by kexxcream
    Problem: To get the index values of an array to print accordingly in value attribute of radio buttons. The array $_SESSION['items']: Array ( [2] => Array ( [category] => 2 [question] => Array ( [6] => Källorna refereras separat [7] => Vissa försök till sammanbindning [8] => En del sammanfattningar [9] => Olika forskningslinjer jämförs och sammanfattas [10] => Kontraster, jämförelser, sammanfattningar; centrala likheter och skillnader framhävs ) [title] => Integration av källorna ) ) I have a PHP function that looks like this: function itemsLayout ($array) { for ($i = 1; $i <= count($array['question']); $i++) { $form .= '<input type="radio" name="'.$array['category'].'" id="'.$array['category'].'" value="INDEX VALUE FOR QUESTION ARRAY HERE">'; } return $form; } PHP code: I get the index by using the following: $key = key($_SESSION['items']); $current = $_SESSION['items'][$key]; And I print the first index by using: echo itemsLayout($current); Question: How do I get the index values 6, 7, 8, 9, 10 to print in the value attribute for each radio button?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >