FAQ Database Discussion Community
java,php,associative-array
I'm from a PHP background, and I'm trying to create a multidimentional array with a difficulty in understanding the Java way of doing things. I thought this could be achieved using JSON and the GSON library, but I'm failing to understand how this is done having followed several tutorials online....
php,oop,associative-array
First we have a property which is the array: private static $_errors = array(); An error can be added by sending it to a function, which will add it to the array: public function addError($error){ self::$_errors[] = $error; } In any function, I can easily add an error as a...
php,arrays,multidimensional-array,associative-array
Consider three associative arrays in php: $a1 = array( "a" => "1", "b" => "2", "c" => "3" ); $a2 = array( "d" => "4", "e" => "5", "f" => "6" ); $a3 = array( "g" => "7", "h" => "8", "i" => "9" ); How would you efficiently combine...
php,arrays,foreach,associative-array,break
I've following code snippet: $aSupportedImages = array('jpg', 'gif', 'png'); foreach($vshare as $file) { if(!in_array(pathinfo($file, PATHINFO_EXTENSION), $aSupportedImages)) $errArr = 'File extension of image is wrong'; echo $errArr; break; } The array $vshare is as follows(output of print_r($vshare);): Array ( [IMG_0004.jpg] => Array ( [0] => https://www.filepicker.io/api/file/UYUkZVHERGufB0enRbJo ) ) I'm not understanding...
php,arrays,json,multidimensional-array,associative-array
I'm retrieving bibliographic data via an API (zotero.org), and it is similar to the sample at the bottom (just way more convoluted - sample is typed). I want to retrieve one or more records and display certain values on the page. For example, I would like to loop through each...
php,associative-array
I have a PHP Code $brandNames = array(); foreach ($maufacturers as $manu) { array_push($brandNames, array($manu->getTitle() => $manu->getUrl())); } print_r($brandNames); I am getting output as Array ( [0] => Array ( [key0] => val0 ) [1] => Array ( [key1] => val1 ) [2] => Array ( [key2] => val2 )...
php,arrays,string,associative-array
I have an associate array. I want to remove duplicate values if the value has appear first. Let's say if DC-30 has appear first, remove all DC-30 in the associate array. If HSD-M has appeared already, remove all HSD-M in the associate array. I'm doing all of this in while($row...
php,arrays,multidimensional-array,associative-array,key-value
I have following $_POST array : Array ( [fileName] => Array ( [0] => 8.png [1] => 2_OnClick_OK.jpg ) [fileLink] => Array ( [0] => https://www.filepicker.io/api/file/zZ993JyCT9KafUtXAzYd [1] => https://www.filepicker.io/api/file/1w3cKCW1TMmytb7md3XQ ) [Submit] => Submit File ) I got the above output after execution of following statement: print_r($_POST); die; // Code to...
dictionary,awk,associative-array
I figured out the following code to find duplicate UIDs in a passwd file, but it doesn't include the first instance (the one that was later duplicated), I ultimately wanted to have a dictionary with UID = [ USER1, USER2 ] but I am not sure how to get it...
r,associative-array
I have a data frame where one column is a factor. I want to map that column into integers. For instance, in the example below, I want to map healthy to the value 2, sick to the value 1, and dead to the value 0. In this example the order...
php,jquery,ajax,json,associative-array
my query gives result query_string and query_string_id i want that result to provide data for ajax and send it to php but i dont know how to send associative array through ajax pls help me to build my code function querySuccessEnds(tx,results) { var len = results.rows.length; console.log("DEMO table: " +...
php,arrays,associative-array,shuffle
I want to do a quiz and here is my array: $questions = array("1+1"=>2,"5+2"=>7,"5+9"=>14,"3+5"=>8,"4+6"=>10,"1+8"=>9,"2+7"=>9, "6+7"=>13,"9+3"=>12,"8+2"=>10,"5+5"=>10,"6+8"=>14,"9+4"=>13,"7+8"=>15, "8+9"=>17,"4+8"=>12,"7+1"=>8,"6+3"=>9,"2+5"=>7,"3+4"=>7); shuffle($questions); foreach($questions as $key => $value) { echo $key.' '; } However, from the above code, I get the output like the following: 0 1 2 3 4 5 6 7 8 9 10...
php,arrays,associative-array
I have this array: 'tab1' => '', 'tab2' => '', 'tab3' => 'active' I want to do array_flip to swap the keys with the values, but the entries with an empty value are not kept. How do I let PHP assign integer keys for me (like with an indexed array)?...
php,for-loop,associative-array
I want to insert two values in an associative array one for the key and second for the value and as i print that array it should contain all a-k as keys and 0-10 as their corresponding values. <?php $z=array("a","b","c","d","e","f","g","h","i","j","k"); $countsub1 = array(); for($i=0;$i<=10;$i++) { $countsub1 = array("$z[$i]","$i"); } print_r($countsub1);...
javascript,prototype,associative-array
With a associative array such as: var m = {}; m['a'] = {id:1, foo:'bar'}; m['b'] = {id:2, foo:'bar'}; Is it possible to create a prototype such as: Array.prototype.hello = function() { console.log('hello'); } m.hello(); This fails because m is an object, so I tired: Object.prototype.hello = function() { console.log('hello'); }...
php,arrays,multidimensional-array,associative-array
I am creating a set of arrays with the following loop: $assessmentArr = explode("&", $assessmentData); foreach($assessmentArr as $data) { $fullArr = explode("_", $data); // Break down to only archetype and value $resultArr = explode("=", $fullArr[2]); //print_r($resultArr); } Which produces the following results: Array ( [0] => community-support [1] => 24...
php,associative-array
I have an associative array and want to print a value...in this case i want to create a foreach to print only [payout] value. Please find below array structure. Array ( [data] => Array ( [0] => Array ( [clicks] => 0 [conversions] => 0 [payout] => $0.00 [erpc] =>...
php,foreach,associative-array
This question already has an answer here: Two arrays in foreach loop 13 answers I've got 2 arrays with the same $key. So arrays are: $users and $new. $users['user_id']=['user_name']; $new['user_id']=['user_color']; How can I foreach them that I could get something like this: foreach (bla bla bla){ echo '<option color="'.$new['user_color'].'"...
php,arrays,codeigniter,codeigniter-2,associative-array
I'm using array in ci . whenever i store i can get only the last elements ! other elements are overwrite. this is my code $table="wp_term_taxonomy"; $data=array(); $this->db->where('taxonomy','Geographical'); $query = $this->db->get($table); if ($query->num_rows() > 0) { foreach ($query->result() as $value) { $terms_id=$value->term_id; $table2="wp_terms"; $this->db->where('term_id',$terms_id); $query2 = $this->db->get($table2); if ($query2->num_rows() >...
arrays,bash,associative-array
This works: $ BAR=(a b c) $ echo "${BAR[1]}" b This, however, doesn't: $ declare -A FOO $ FOO=(a b c) bash: FOO: a: must use subscript when assigning associative array bash: FOO: b: must use subscript when assigning associative array bash: FOO: c: must use subscript when assigning associative...
php,mysql,select,sql-injection,associative-array
I am trying to set up PHP queries for MySQL in a way to prevent SQL injection (standard website). I had a couple of INSERT queries where changing this worked well but on the following SELECT I keep getting an error since the update and it looks like the while...
php,arrays,associative-array
QUESTION: In the second (following) code snippet, in the inner foreach loop (that is the foreach loop nested in another foreach loop), the $value corresponds to an element of the $studentCoursesStudied, and NOT the $studentCoursesStudied array itself, right? The correct way to access the value of an element of the...
oracle,plsql,associative-array
Im trying to delete a set of tables and afterwards I want to recreate them using as select from. For couriousity I wanted to do this with an associative array. Unfortunately something is messed up, several errors appear and I can't find the reasons. This is the code: DECLARE TYPE...
php,arrays,associative-array
I have the array: array(2=>'0',3=>'1',5=>'3',4=>'4',7=>'2') Note: Nothing seems to be in order. So leave the plan to find a numeric order. How can I fixed the i'th element of this associative array? For example when i is 4 the value should be 4, when i is 1 the value should...
php,multidimensional-array,associative-array
I have an associative array that is essentially static dummy data for a mock-up that is standing in for a database. I am trying to replicate what GROUPBY YEAR AND TitleText would do in MySQL and I can make it work on one field - either TitleText or YEAR using...
javascript,hashmap,associative-array
We learned there are many different hashing algorithms/functions, I'm curious which one is used by javascript (v8, if the implementation matters).
php,arrays,multidimensional-array,associative-array
I'm trying to manipulate an associative multidimensional array. I've extracted the keys from an array that I want to apply to another's values . . . These are the keys that I've extracted in another function $keys = array ( "id" => "id", "addr_street_num" => "addr_street_num", "addr_street" => "addr_street", "price"...
php,arrays,serialization,associative-array,key-value
I've an array titled $aFilter. Upon serializing it few numbers are getting inserted into it. I'm not understanding why did it happen? Why did it insert the numbers and in which pattern? Can someone please guide me what actually this serialize() does and generates such kind of output in an...
php,arrays,associative-array
I have an array like this.. array(26053) { [0]=> array(1) { ["New York"]=> array(10) { ["state"]=> string(8) "New York" ["state_code"]=> string(0) "" ["country_code"]=> string(1) "1" ["country"]=> string(24) "United States Of America" ["lat"]=> string(0) "" ["long"]=> string(0) "" ["city_id"]=> string(5) "70834" ["country_id"]=> string(4) "6532" ["country_iso"]=> string(2) "US" ["orignal_name"]=> string(1) "" }...
php,arrays,multidimensional-array,associative-array
i wanted to covert array values into a multidimensional associative array. Array size can be dynamic. Array to be converted: Array ( [0] => abc [1] => 0 [2] => xyz [3] => 0 ) Expected Output: Array ( [abc] => Array ( [0] => Array ( [xyz] => Array...
php,arrays,foreach,associative-array,key-value
I've an array titled $photos as follows: Array ( [0] => Array ( [fileURL] => https://www.filepicker.io/api/file/UYUkZVHERGufB0enRbJo [filename] => IMG_0004.JPG ) [1] => Array ( [fileURL] => https://www.filepicker.io/api/file/WZeQAR4zRJaPyW6hDcza [filename] => IMG_0003.JPG ) ) Now I want to create a new array titled $values as follows : Array ( [vshare] => Array...
php,arrays,key,associative-array,value
So I have an array: Array ( [Favorite-Search-Engines] => Array ( [0] => Google [1] => Yahoo [2] => Bing [3] => DuckDuckGo ) ) I want the user to be able to remove a key, but if they remove one: Array ( [Favorite-Search-Engines] => Array ( [0] => Google...
javascript,multidimensional-array,while-loop,associative-array
i have a problem width this simple code... I created an associative array width a while cycle that should be constituted of four elements... the problem is that it works only width the first two elements : matrice[1][1] and matrice[1][2]... not width matrice[2][1] and matrice[2][2] thanks in advice! <html> <head>...
php,arrays,multidimensional-array,key,associative-array
This question already has an answer here: Is there a function to extract a 'column' from an array in PHP? 13 answers Let's say that I have an array like this: $people = array( array( 'name' => 'Bob', 'job' => 'Carpenter' ), array( 'name' => 'George', 'job' => 'Programmer'...
php,arrays,multidimensional-array,associative-array,key-value
I've an array titled $aRows as follows : Array ( [0] => Array ( [is_liked] => [comment_id] => 262 [parent_id] => 0 [type_id] => document [item_id] => 160 [user_id] => 991 [owner_user_id] => 991 [time_stamp] => 1425364320 [update_time] => 0 [update_user] => [rating] => [ip_address] => 125.17.118.118 [author] => 1592...
php,mysqli,associative-array
I am having some issues with the below, wanting to add the query result "id" as the key to the value "concat" -- Do I need a foreach for this? What is the best way? $concatCol = mysqli_query( $connS, "SELECT id, ShipmentNumber, InvoiceNumber, BillofLading from testTable"); $data =array(); while ($row...
java,json,data-structures,associative-array
I need to store key-value pairs inside key-value pairs and so on as required by the data. I tried to achieve this using Hash-Map in java but it didn't work as I expected it to. Since, my data has multiple name->value pairs, but the Hash-Map keeps overwriting the name key's...
php,html,arrays,associative-array,strip-tags
This question already has an answer here: Updating arrays in an array using foreach 3 answers I've an array titled $aMessages. Actually it's quite a huge array but for your reference I'm printing below only first three elements from it: Array ( [0] => Array ( [message_id] => 240...
php,arrays,multidimensional-array,associative-array,key-value
I've a large array titled $files. For understanding purpose I'm just putting small part of this array as follows(output of print_r($files);): Array ( [name] => Array ( [0] => course_error.png [1] => before_login.png ) [type] => Array ( [0] => image/png [1] => image/png ) [tmp_name] => Array ( [0]...
php,arrays,foreach,associative-array
I wish to update just the ["distanceTimeFromNextPoint"] element in an associative array I have created in PHP. I am trying to update the following array structure: Array ( [0] => Array ( [Total time] => 0:00 [0] => Array ( [place] => Spanish steps [distanceTimeFromNextPoint] => ) [1] => Array...
php,arrays,substring,associative-array
This is my array (input): $value = array("jan01" => "01", "feb02" => "02", "mar03" => "03", "apr04" => "04"); I am using this code to get the array keys: implode(" ", array_map("ucwords", array_keys($value))); Now my problem is I want to get all keys by triming the last two characters of...
php,mysql,codeigniter,associative-array
using CI I'm trying to set up query with three parameters: user_id, content_type and content_id in which content_id is array of IDs. So I need to get up with something like this: SELECT name FROM content WHERE user_id = 2 AND content_type = file AND (content_id = 4 OR content_id...
php,arrays,associative-array
Quick and short question. The code below is just the way I want it to be. For some reason, however, it doesn't work. No errors are shown (error_reporting is -1) and nothing happens. <?php $data_clean_type = 'numeric'; $data_clean_filter = array('alpha' => '/^[a-zA-Z]*$/', 'numeric' => '/^[0-9]*$/', 'alphanumeric' => '/^[a-zA-Z0-9]*$/'); if(in_array($data_clean_type, $data_clean_filter))...
linux,bash,shell,awk,associative-array
Originally, the file has its contents like this: 1.2.3.4: 1,3,4 1.2.3.5: 9,8,7,6 1.2.3.4: 4,5,6 1.2.3.6: 1,1,1 after I have tried sorting it incorrectly I have this: 1.2.3.4: 1,3,4,4,5,6, 1.2.3.5: 9,8,7,6, 1.2.3.6: 1,1,1, I want to sort it into the following format: 1.2.3.4: 1,3,4,5,6 1.2.3.5: 6,7,8,9 1.2.3.6: 1 but how do...
php,arrays,codeigniter,codeigniter-2,associative-array
Array ( [0] => Array ( [name] => Chennai [id] => 98 ) [1] => Array ( [name] => India [id] => 99 ) [2] => Array ( [name] => South India [id] => 100 ) [3] => Array ( [name] => North India [id] => 101 ) [4] =>...
javascript,arrays,associative-array
So I know how to set the key dynamically like this: var hashObj = {}; hashObj[someValue] = otherValue; But I haven't seen any answer regarding map(): var list = ['a', 'b', 'c']; var hashObject = list.map(function(someValue) { return { someValue: 'blah' }; }); // should return: [ {'a': 'blah'}, {'b':...
php,arrays,preg-replace,newline,associative-array
I have an associative array titled $allFeeds (after executing print_r($allFeeds);) as follows: Array ( [0] => Array ( [feed_status] => Vividly dug<br />Hchxhh civic<br />Hchxhh cuffing<br />Viccydyduiggigig<br />Bivucfigigudufyd<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Jfufjfufigijdgdjcj<br />Crucify fix<br />Ogives gif<br />Gucucvi<br />Jfufjfufigijdgdjcj<br />Juicy fiduciary<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Jcjcufufydxy<br />Igufucuducufuf<br...
php,multidimensional-array,associative-array
I've got a very large JSON file that I've converted into an array. The code you see below is the result of var_dump($array['talents']) (for those wondering, yes, this is me attempting to use Blizzard Entertainment's API) Maybe I just missed that day at PHP school, but I just can't seem...
php,arrays,associative-array
I'm trying to call methods while building an array. I am building a fairly large config array which contains many re usable blocks. This is the array that I'd like to get: array( "masterKey" => array( "myKey" => array( "valueField" => "hi" ), "anotherKey" => array( "valueField" => "hi again"...
php,csv,multidimensional-array,associative-array
I'm trying to create a multidimensional array in PHP where the inner arrays are associative for the following example CSV string $csv: # Results from 2015-06-16 to 2015-06-16. date,time,label,artist,composer,album,title,duration 2015-06-16,12:00 AM,Island,U2,"Clayton- Adam,The Edge,Bono,Mullen- Larry- Jr",Songs Of Innocence,SONG FOR SOMEONE,03:46 2015-06-16,12:04 AM,Lowden Proud,"Fearing & White, Andy White, Stephen Fearing","White- Andy,Fearing- Stephen",Tea...
php,arrays,codeigniter-2,associative-array
Array ( [0] => Array ( [post_id] => 70 [percentage] => 66.666666666667 ) [1] => Array ( [post_id] => 72 [percentage] => 44.444444444444 ) [2] => Array ( [post_id] => 74 [percentage] => 11.111111111111 ) [3] => Array ( [post_id] => 82 [percentage] => 60 ) ) How to sort...
php,arrays,multidimensional-array,associative-array,error-reporting
I wrote a program to define an associative array titled $aFilter and tried to print it but I'm not able to. I tried two ways to achieve this but couldn't succeed. Following are the two ways I tried. Way 1: <!DOCTYPE html> <html> <body> <?php $aFilter = Array ( ['pages']...
php,html,arrays,string,associative-array
I've an array associative array titled $comments as follows : Array ( [0] => Array ( [text] => Uploading Photo for comment <div class="comment_attach_image"> <a title="colorbox" href="https://www.filepicker.io/api/file/CnYTVQdATAOQTkMxpAq4" ><img src="https://www.filepicker.io/api/file/CnYTVQdATAOQTkMxpAq4" height="150px" width="150px" /></a> <a href="https://www.filepicker.io/api/file/CnYTVQdATAOQTkMxpAq4" class="comment_attach_image_link_dwl">Download</a> </div> ) [1] => Array (...
php,arrays,associative-array
I have a query that returns an associative array. In that array are fields I must remove before output. I've tried array_diff and unset, but not having any luck. The beginning array: Array ( [id] => 13461 [ln] => 605717 [ptyp] => COND [lag] => 86484 [st] => S [lp]...
php,arrays,for-loop,associative-array
$eventname = array( "April" => array("April Fool", 4), "May" => array("Labour Day", 1) ); How can I apply for loop and print the element of the array?...
php,arrays,json,associative-array,key-value
I'm getting following JSON request data : data = "{\"photo\":[{\"fileURL\":\"https:\\/\\/www.filepicker.io\\/api\\/file\\/RqAN2jZ7ScC8eOx6ckUE\",\"filename\":\"IMG_0003.JPG\"},{\"fileURL\":\"https:\\/\\/www.filepicker.io\\/api\\/file\\/XdwtFsu6RLaoZurZXPug\",\"filename\":\"IMG_0004.JPG\"}]}"; I want to make an array from the above JSON data into following format : Array ( [vshare] => Array ( [IMG_0003.JPG] => Array ( [0] => https://www.filepicker.io/api/file/RqAN2jZ7ScC8eOx6ckUE ) [IMG_0004.JPG] => Array ( [0] =>...
php,arrays,multidimensional-array,associative-array,key-value
I've an array titled $aFilter as follows(Output of print_r($aFilter);): Currently only one internal array element is shown but it can contain many such elements. So consider the case with multiple internal array elements. Array( [0] => Array( [filter_id] => 84 [user_id] => 984 [item_id] => 244 [type_id] => user [feed_type]...
php,html,arrays,string,associative-array
I've an array of comments titled $comments. The actual array could be huge in size, it may contain hundreds of such elements. For your understanding I've added only 10 elements to it as follows : Array ( [0] => Array ( [text] => Second Comment Added ) [1] => Array...
php,arrays,foreach,associative-array,file-extension
I've following array of file extensions titled $aSupportedImages: Array ( [0] => jpeg [1] => jpg [2] => gif [3] => png ) I've another array titled $values as follows : Array ( [vshare] => Array ( [course_error.png] => Array ( [0] => https://www.filepicker.io/api/file/Y0n99udSqS6ZJWYeYcUA ) [before_login.png] => Array ( [0]...
bash,awk,associative-array
The first file I have (file1.txt): ID name start end ID3 pot 15 28 ID2 cat 12 25 ID4 dog 20 30 ID1 turtle 1 10 And another file (file2.txt): key ID1 ID2 ID3 ID4 23 1.5 2.5 1.2 3.4 5 1.4 2.3 4.2 1.4 21 1.2 2.4 3.5 1.9...
php,multidimensional-array,associative-array
I am attempting to print out a table of the PHP multi-dimensional associative arrays. There are arrays for the class, assignments, students, scores. I am familiar with MySQL queries, but I am not sure how to print out the table from a PHP multi-dimensional associative arrays. My thought process to...
php,arrays,image,associative-array,imageurl
I'm using one CMS written in PHP. I'm making use of it's built-in functions to do the operations. At one place I want to get the path of an image for it following is the code which is working fine and returning the image. $sUserProfileImage = Phpfox::getLib('image.helper')->display(array_merge(array('user' => Phpfox::getService('user')->getUserFields(true)), array...
php,arrays,session,associative-array
This question already has an answer here: Notice: Unknown: Skipping numeric key 1 in Unknown on line 0 1 answer example: $_SESSION['10'] = 'testing'; echo $_SESSION['10']; The above will not print out anything...i found out(after a long time of frustration) that you cannot use a string numeral as a...
linux,bash,shell,unix,associative-array
I am currently trying to loop through an associative array. This array contains values with the same key. However, when I tried to loop through it, I only get one set of results. How can I loop through all the values containing the same key? #!/bin/bash/ declare -A details=( [dog]="golden...
delphi,tree,associative-array,tdictionary,delphi-xe8
I just wrote a very simple class to test the TDictionary<> Class in Delphi XE8. When i try to show the records that i added, it brings me an Access Violation error, i don't understand why? Here is my class unit Unit3; interface uses Classes, System.SysUtils, System.Types, REST.Types, System.JSON, Data.Bind.Components,...
c++,c++11,associative-array,c++-standard-library
I was looking for the most efficient and expressive way to remove the last element from a std::map. I tried: #include <map> int main() { std::map<int, int> m; m.insert(std::make_pair(1,1)); m.erase(m.crbegin()); return 0; } The code does not compile, since std::map::erase can take only std::map::const_iterator. Moreover, prior to C++11 it could...
php,arrays,multidimensional-array,associative-array
I have stored many arrays in a single associative array and assigned key values simple number counting. How can I extract one of those array from the associative array? my array: $arr = array( 1 => array("ask","bat","cod","dig","egg","fur","gap","hay","ice","jar","kin","lee"), 2 => array("add","big","cap","day","eye","fat","gel","hop","ink","jog","key","law"), 3 => array("axe","bin","cel","don","eat","fig","gig","hut","ion","jin","kid","lip") ); I want to store the array...
php,arrays,multidimensional-array,associative-array,key-value
I've on associative array titled $group_list. When I print it using print_r($grouop_list) it prints following content: Pages_Component_Controller_List Object ( [data] => Array ( [0] => Array ( [vanity_url] => [page_type] => 1 [category_name] => Athletic [profile_server_id] => 0 [profile_user_image] => [is_liked] => 592 [page_id] => 174 [app_id] => 0 [view_id]...
php,arrays,associative-array
what i need to need i need to fetch some key values and store in another array. api data Array ( [0] => Array ( [id] => 180462 [des] => India International Bearing Expo New Delhi is a 3 day event being held from 5th June to the 7th June...
php,string,associative-array
I have a PHP associative array that I am trying to extract data from: array(18) { ["body"]=> string(34) "Hey! Let me know if you got this"} The above array is stored in a variable called $firstChildData, and when I try to run the following line, I get the result below...
perl,data-structures,hashtable,associative-array,perl-data-structures
I want to read and save the content of a file in a hash of array. The first column of each row would be the key. Then, I want to read the files in a directory and add the file name to the end of the array according to the...