Search Results

Search found 16413 results on 657 pages for 'array manipulation'.

Page 13/657 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Copy a multi-dimentional array by Value (not by reference) in PHP.

    - by Simon R
    Language: PHP I have a form which asks users for their educational details, course details and technical details. When the form is submitted the page goes to a different page to run processes on the information and save parts to a database. HOWEVER(!) I then need to return the page back to the original page, where having access to the original post information is needed. I thought it would be simple to copy (by value) the multi-dimensional (md) $_POST array to $_SESSION['post'] session_start(); $_SESSION['post'] = $_POST; However this only appears to place the top level of the array into $_SESSION['post'] not doing anything with the children/sub-arrays. An abbreviated form of the md $_POST array is as follows: Array ( [formid] = 2 [edu] = Array ( ['id'] = Array ( [1] = new_1 [2] = new_2 ) ['nameOfInstitution'] = Array ( [1] = 1 [2] = 2 ) ['qualification'] = Array ( [1] = blah [2] = blah ) ['grade'] = Array ( [1] = blah [2] = blah ) ) [vID] = 61 [Submit] = Save and Continue ) If I echo $_SESSION['post']['formid'] it writes "2", and if I echo $_SESSION['post']['edu'] it returns "Array". If I check that edu is an array (is_array($_SESSION['post']['edu])) it returns true. If I echo $_SESSION['post']['edu']['id'] it returns array, but when checked (is_array($_SESSION['post']['edu]['id'])) it returns false and I cannot echo out any of the elements. How do I successfully copy (by value, not by reference) the whole array (including its children) to an new array?

    Read the article

  • Reverse alphabetic sort multidimensional PHP array maintain key

    - by useyourillusiontoo
    I'm dying here, any help would be great. I've got an array that I can sort a-z on the value of a specific key but cannot sort in reverse z-a. sample of my array which i'd like to sort by ProjectName (z-a): Array ( [0] => Array ( [count] => 1 [ProjectName] => bbcjob [Postcode] => 53.471922,-2.2996078 [Sector] => Public ) [1] => Array ( [count] => 1 [ProjectName] => commercial enterprise zone [Postcode] => 53.3742081,-1.4926439 [Sector] => Public ) [2] => Array ( [count] => 1 [ProjectName] => Monkeys eat chips [Postcode] => 51.5141492,-0.2271227 [Sector] => Private the desired results would be to maintain the entire array key - value structure but with the order: Monkeys eat chips Commericial enterprise zone bbcjob I hope this makes sense

    Read the article

  • Android: Defined array resource not found ?!

    - by David
    Hi, i have a strange (?) error in my android application. I have defined some arrays in values/arrays.xml the following way: <?xml version="1.0" encoding="utf-8"?> <resources> <array name="perimeter"> <item>10 miles</item> <item>20 miles</item> <item>30 miles</item> </array> <array name="regvalues"> <item>1</item> <item>2</item> <item>3</item> </array> </resources> Now I want to use them in a ListPreference for a PreferenceActivity (defined by an xml file). So i set android:entries="@array/perimeter" android:entryValues="@array/regvalues" for this ListPreference. When I try to use this on my device the app crashes. (NullPointer in Dialog.close()) If I try to use the regvalues-items as Entries for the ListPreference i get a NullPointer in ArrayAdapter.createViewFromResource(int, View, ViewGroup, int) line: 355 So there seems to be sth wrong with the regvalues array. But what ?!? Eclipse shows me no errors at compile time. So everything in the xml-file and java-code is written correctly and there are no typos. Where is the problem?!?

    Read the article

  • php how to serialize array of objects?

    - by hequ
    Hello, I have small class called 'Call' and I need to store these calls into a flat file. I've made another class called 'CallStorage' which contains an array where I put these calls into. My problem is that I would like to store this array to disk so I could later read it back and get the calls from that array. I've tried to achieve this using serialize() and unserialize() but these seems to act somehow strange and part of the information gets lost. This is what I'm doing: //write array to disk $filename = $path . 'calls-' . $today; $serialized = serialize($this->array); $fp = fopen($filename, 'a'); fwrite($fp, $serialized); fclose($fp); //read array from serialized file $filename = $path . 'calls-' . $today; if (file_exists($filename)) { $handle = fopen($filename, 'r'); $contents = fread($handle, filesize($filename)); fclose($handle); $unserialized = unserialize($contents); $this->setArray($unserialized); } Can someone see what I'm doing wrong, or what. I've also tried to serialize and write arrays that contains plain strings. I didn't manage to get that working either.. I have a Java background so I just can't see why I couldn't just write an array to disk if it's serialized. :)

    Read the article

  • For each result in MySQL query, push to array (complicated)

    - by Dylan Taylor
    Okay, here's what I'm trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then within that ID in the array, I need to add more data from the rows. A multi-dimensional array. Here's my code thus far. $query = "SELECT * FROM posts ORDER BY id DESC LIMIT 10"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $id = $row["id"]; $post_title = $row["title"]; $post_text = $row["text"]; $post_tags = $row["tags"]; $post_category = $row["category"]; $post_date = $row["date"]; } As you can see I haven't done anything with arrays yet. Here's an ideal structure I'm looking for, just incase you're confused. The master array I guess you could call it. We'll just call this array $posts. Within this array, I have one array for each row returned in my MySQL query. Within those arrays there is the $post_title, $post_text, etc. How do I do this? I'm so confused.. an example would be really appreciated. -Dylan

    Read the article

  • PHP Modify Array

    - by Ozzy
    Hi all, I have the following array: array(a, a, a, b, b, c, c, c, c, d, d); When I loop through it and echo it, the result is: a a a b b c c c c d d How ever I want to echo it in such a way that it displays: a b c d a b c d a c c Here is the array in a grid to better explain what im trying to achieve Current a a a b b c c c c d d What im tryin to do a b c d a b c d a c c How would I do this?

    Read the article

  • A simple string array Iteration in C# .NET doesn't work

    - by met.lord
    This is a simple code that should return true or false after comparing each element in a String array with a Session Variable. The thing is that even when the string array named 'plans' gets the right attributes, inside the foreach it keeps iterating only over the first element, so if the Session Variable matches other element different than the first one in the array it never returns true... You could say the problem is right there in the foreach cicle, but I cant see it... I've done this like a hundred times and I can't understand what am I doing wrong... Thank you protected bool ValidatePlans() { bool authorized = false; if (RequiredPlans.Length > 0) { string[] plans = RequiredPlans.Split(','); foreach (string plan in plans) { if (MySessionInfo.Plan == plan) authorized = true; } } return authorized; }

    Read the article

  • Sorting a multidimensional array in objective-c

    - by Zen_silence
    Hello, I'm trying to sort a multidimensional array in objective-c i know that i can sort a single dimensional array using the line of code below: NSArray *sortedArray = [someArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; I can't seem to figure out how to sort a 2D array like the one below: ( ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY"), ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY"), ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY") ); If someone could provide me code that would sort the array by SOME_CATEGORY it would be of great help to me. Thanks, Zen_Silence

    Read the article

  • Java HashSet<Integer> to int array

    - by jackweeden
    I've got a HashSet with a bunch of (you guessed it) integers in it. I want to turn it into an array, but calling hashset.toArray(); returns an array of Object type. This is fine, but is there a better way to cast it to an array of int, other than iterating through every element manually? A method I want to pass it to void doSomething(int[] arr) Won't accept the Object[] array, even if I try casting it like doSomething((int[]) hashSet.toArray());

    Read the article

  • Perl, array referencing

    - by Mike
    Consider this Perl code my @a=[[1]]; print $a[0][0] . "\n"; **output** ARRAY(0x229e8) Why does it print an Array instead of 1? I would have expected @a to create an array of size 1 with a reference to a second array containing only one element, 1

    Read the article

  • from one-dimensional to two-dimensional array

    - by Thijs
    Hi again, I have this PHP one dimensional array: Array ( [Female--N] => 11 [Male--N] => 11 [Humans--N] => 11 [Adult--N] => 8 [Adolescent--N] => 8 [Reaction Time-physiology--N] => 6 [Acoustic Stimulation-methods--N] => 6 [Schizophrenia-genetics--Y] => 5 [Motion Perception--N] => 3 ) And i want a new array from this that looks like (i think this tow-dimensional..?): Array ( [Female][N] => 11 [Male][N] => 11 [Humans][N] => 11 [Adult][N] => 8 [Adolescent][N] => 8 [Reaction Time-physiology][N] => 6 [Acoustic Stimulation-methods][N] => 6 [Schizophrenia-genetics][Y] => 5 [Motion Perception][N] => 3 ) Can i use split method on key elements? Little bit harder... i also need to split on the single '_' underscore, i did this to prevent the columns getting mixed up... But the example below doesn't do the job right... $new_array = array(); foreach($MeshtagsArray as $key => $value) { $parts = explode('__', $key, 2); $parts2 = explode('_', $key, 2); $new_array[] = array( 'discriptor' => $parts[0], 'qualifier' => $parts2[1], 'major' => $parts[1], '#occurence' => $value ); So the output should be something like: [0] => Array ( [discriptor] => Female [qualifier] => [major] => N [#occurence] => 11 ........ [5] => Array ( [discriptor] => Reaction Time [qualifier] => physiology [major] => N [#occurence] => 6 Best regards, Thijs

    Read the article

  • list or container O(1)-ish insertion/deletion performance, with array semantics

    - by Chris Kaminski
    I'm looking for a collection that offers list semantics, but also allows array semantics. Say I have a list with the following items: apple orange carrot pear then my container array would: container[0] == apple container[1] == orangle container[2] == carrot Then say I delete the orange element: container[0] == apple container[1] == carrot I don't particularly care if sort order is maintained, I'd just like the array values to function as accelerators to the list items, and I want to collapse gaps in the array without having to do an explicit resizing.

    Read the article

  • Replace string key of PHP array

    - by poru
    Hello, I have an array in PHP which looks like that: $test = array('3' => 5); How could I replace the stringed array key 3? I tried: $test['3'] = "New value" but it don't work, it look like that after that: array('3' => 5, 3 => "New value")

    Read the article

  • declare or convert a string to array format

    - by Jamex
    Hi, How to convert a string format into an array format? I have a string, $string = 'abcde' I want to convert it to a 1 element array $string[0] = 'abcde' Is there a built in function for this task?? or the shortest way is to $string = 'abcde'; $array[0] = $string; $string = $array; TIA

    Read the article

  • declare or convert a string to array format PHP

    - by Jamex
    How to convert a string format into an array format? I have a string, $string = 'abcde' I want to convert it to a 1 element array $string[0] = 'abcde' Is there a built in function for this task? Or the shortest way is to $string = 'abcde'; $array[0] = $string; $string = $array; TIA

    Read the article

  • Compare array in loop

    - by user3626084
    I have 2 arrays with different sizes, in some cases one array can have more elements than the other array. However, I always need to compare the arrays using the same id. I need to get the other value with the same id in the other array I have tried this, but the problem happens when I compare the two arrays in a loop when the other array has more elements than one, because duplicate the loop and data , and it does not work. Here is what I've tried: <?php /// Actual Data Arrays /// $data_1=array("a1-fruits","b1-apple","c1-banana","d1-chocolate","e1-pear"); $data_2=array("b1-cars","e1-eggs"); /// for ($i=0;$i<count($data_1);$i++) { /// Explode ID $data_1 /// $exp_id=explode("-",$data_1[$i]); /// for ($h=0;$h<count($data_2);$h++) { /// Explode ID $data_2 /// $exp_id2=explode("-",$data_2[$h]); /// if ($exp_id[0]=="".$exp_id2[0]."") { print "".$data_2[$h].""; print "<br>"; } else { print "".$data_1[$i].""; print "<br>"; } /// } /// } ?> I want the following values : "a1-fruits" "b1-cars" "c1-banana" "d1-chocolate" "e1-eggs" Yet, I get this (which isn't what I want): a1-fruits a1-fruits b1-cars b1-apple c1-banana c1-banana d1-chocolate d1-chocolate e1-pear e1-eggs I tried everything I know and try to understand how I can do this because I don't understand how to compare these two arrays. The other problem is when one size has more elements than the other, the comparison always gives an error. I FIND THE SOLUTION TO THIS AND WORKING IN ALL : <?php /// Actual Data Arrays /// $data_1=array("a1-fruits","b1-apple","c1-banana","d1-chocolate","e1-pear"); $data_2=array("b1-cars","e1-eggs","d1-chocolate2"); /// for ($i=0;$i<count($data_1);$i++) { $show="bad"; /// Explode ID $data_1 /// $exp_id=explode("-",$data_1[$i]); /// for ($h=0;$h<count($data_2);$h++) { /// Explode ID $data_2 /// $exp_id2=explode("-",$data_2[$h]); /// if ($exp_id2[0]=="".$exp_id[0]."") { $show="ok"; print "".$data_2[$h]."<br>"; } /// } if ($show=="bad") { print "".$data_1[$i].""; print "<br>"; } /// } ?>

    Read the article

  • Sort an array by a child array's value

    - by Evan
    I have an array composed of arrays. I want to sort the parent array by a property of the child arrays. Here's an example array(2) { [0]=> array(3) { [0]=> string(6) "105945" [1]=> string(10) "First name" [2]=> float(0.080878465391) } [1]=> array(3) { [0]=> string(6) "109145" [1]=> string(11) "Second name" [2]=> float(0.0504154818384) } I would like to sort the parent array by [2] ascending in the child arrays, so in this case the result would be the child arrays reversed (.05, 08). Is this possible using any of the numerous PHP sort functions?

    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

  • To not iterate through function of Array object if it is added to Array prototype

    - by Rishat Muhametshin
    According to the way to add indexOf method to Array class in IE6, how do I now reject this method from iterating through any random array? For example: Array.prototype.indexOf = function(needle) { ... }; var array = [1, 2, 3]; for (var i in array) { document.write(i + ': ' + array[i]); } gives output 0: 1 1: 2 2: 3 indexOf: function ... How can I skip indexOf property and stop iterating on it without adding any code to where for(...) is called?

    Read the article

  • How to assign the array key a value, when the key name is itself a variable

    - by Matrym
    How do I identify an item in a hash array if the key of the array is only known within a variable? For example: var key = "myKey"; var array = {myKey: 1, anotherKey: 2}; alert(array.key); Also, how would I assign a value to that key, having identified it with the variable? This is, of course, assuming that I must use the variable key to identify which item in the array to alert. Thanks in advance!

    Read the article

  • Accessing 2D array and passing string to label.text

    - by Amir
    Hi. I'm trying to create 2D array and initialize it with NSStrings. When I try to copy content of a cell from the array to a label.text, the application crashes. NSMutableArray *array = [NSMutableArray arrayWithCapacity:0]; [array addObject:[NSMutableArray arrayWithObjects: [NSArray arrayWithObjects: @"0-0", @"0-1", @"0-2", nil], [NSArray arrayWithObjects: @"1-0", @"1-1", @"1-2", nil], [NSArray arrayWithObjects: @"2-0", @"2-1", @"2-2", nil], nil]]; label.text = [[array objectAtIndex:0] objectAtIndex:0]; Any idea why and what am I doing wrong?

    Read the article

  • PHP Sort a multidimensional array by element containing date

    - by user270797
    I have an array such as: Array ( [0] => Array ( [id] => 2 [type] => comment [text] => hey [datetime] => 2010-05-15 11:29:45 ) [1] => Array ( [id] => 3 [type] => status [text] => oi [datetime] => 2010-05-26 15:59:53 ) [2] => Array ( [id] => 4 [type] => status [text] => yeww [datetime] => 2010-05-26 16:04:24 ) ) Can anyone suggest a way to sort/order this based on the datetime element?

    Read the article

  • Adding to a multidimensional array in PHP

    - by b. e. hollenbeck
    I have an array being returned from the database that looks like so: $data = array(201 => array('description' => blah, 'hours' => 0), 222 => array('description' => feh, 'hours' => 0); In the next bit of code, I'm using a foreach and checking the for the key in another table. If the next query returns data, I want to update the 'hours' value in that key's array with a new hours value: foreach ($data as $row => $value){ $query = $db->query($sql); if ($result){ $value['hours'] = $result['hours']; } I've tried just about every combination of declarations for the foreach loop, but I keep getting the error that it's a non-object. Surely this is easier than my brain is perceiving it.

    Read the article

  • slicing 2d numpy array

    - by MedicalMath
    I have a 2d numpy array called FilteredOutput that has 2 columns and 10001 rows, though the number of rows is a variable. I am trying to take the 2nd column of FilteredOutput and use it to populate a new 1d numpy array called timeSeriesArray using the following line of code: timeSeriesArray=p.array(FilteredOutput[:,0]) I got this syntax from the following link. But the problem is that I am getting the following error message: TypeError: list indices must be integers, not tuple Can anyone show me the proper syntax for populating the 1d array timeSeriesArray with the contents of the second column of the 2d array FilteredOutput?

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >