I have an array like  $value = array('key1'=&gt;'value1','key2'=&gt;'value2','key3'=&gt;'value3');   I want to convert this array to the following string.  key1=value1&amp;key2=value2&amp;key3=value3   I have tried with implode function, but it returns only values of the array  implode($value,"&amp;"); // returns value1&amp;value2&amp;value3   Is there any simple way to achieve this ?
67765
I'm looking for the name of the PHP function to build a query string from an array of key value pairs. Please note, I am looking for the built in PHP function to do this, not a homebrew one (that's all a google search seems to return). There is one, I just can't remember its name or find it on php.net. IIRC its name isn't that intuitive.
122787
Is there a way to print an entire array ([key]=value) without looping over all elements?    Assume I have created an array with some elements:    declare -A array array=([a1]=1 [a2]=2 ... [b1]=bbb ... [f500]=abcdef)   I can print back the entire array with  for i in "${!array[@]}" do echo "${i}=${array[$i]}" done   However, it seems bash already knows how to get all array elements in one "go" - both keys ${!array[@]} and values ${array[@]}.    Is there a way to make bash print this info without the loop?  Edit: typeset -p array does that! However I can't remove both prefix and suffix in a single substitution:  a="$(typeset -p array)" b="${a##*(}" c="${b%% )*}"   Is there a cleaner way to get/print only the key=value portion of the output?
43371
PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the empty() function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?
60856
I have a string that looks like this:  "Name1=Value1;Name2=Value2;Name3=Value3"   Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this:  dict = {     "Name1": "Value1",     "Name2": "Value2",     "Name3": "Value3" }   I have looked through the modules available but can't seem to find anything that matches.    Thanks, I do know how to make the relevant code myself, but since such smallish solutions are usually mine-fields waiting to happen (ie. someone writes: Name1='Value1=2';) etc. then I usually prefer some pre-tested function.  I'll do it myself then.
29178
I have the following code:  if ($_POST['submit'] == "Next") {     foreach($_POST['info'] as $key =&gt; $value) {         echo $value;     } }   How do I get the foreach function to start from the 2nd key in the array?
26241
I have the following string array:  var sa = new string[] {"yabba","dabba","doo"};   I can convert it to "yabba, dabba, doo" it using string.Join() but what is the super-cool LINQ way of doing it?  The Join extension method seems promising but for a novice like me very confusing.
3020
How can I remove duplicate values from a multi-dimensional array in PHP?  Example array:  Array (     [0] =&gt; Array     (         [0] =&gt; abc         [1] =&gt; def     )      [1] =&gt; Array     (         [0] =&gt; ghi         [1] =&gt; jkl     )      [2] =&gt; Array     (         [0] =&gt; mno         [1] =&gt; pql     )      [3] =&gt; Array     (         [0] =&gt; abc         [1] =&gt; def     )      [4] =&gt; Array     (         [0] =&gt; ghi         [1] =&gt; jkl     )      [5] =&gt; Array     (         [0] =&gt; mno         [1] =&gt; pql     )  )
7083
I need to  an object to . I'm using . Is there a "standard" way to do this?  My specific situation: I have an array defined as shown below:  var countries = new Array(); countries[0] = 'ga'; countries[1] = 'cd'; ...   and I need to turn this into a string to pass to  like this:  $.ajax({     type: "POST",     url: "Concessions.aspx/GetConcessions",     data: "{'countries':['ga','cd']}", ...
29869
In php, I often need to map a variable using an array ... but I can not seem to be able to do this in a one liner. c.f. example:  // the following results in an error: echo array('a','b','c')[$key];  // this works, using an unnecessary variable: $variable = array('a','b','c'); echo $variable[$key];   This is a minor problem, but it keeps bugging every once in a while ... I don't like the fact, that I use a variable for nothing ;)
1821
I have a one-dimensional array of strings in JavaScript that I'd like to turn into a comma-separated list. Is there a simple way in garden-variety JavaScript (or jQuery) to turn that into a comma-separated list? (I know how to iterate through the array and build the string myself by concatenation if that's the only way.)
57618
foreach((get_the_category()) as $category) {     echo $category-&gt;cat_name . ', ';  }   So I'm echoing it like this because I don't want the categories to appear as hyperlinks, I just want the cat names.  The problem is I can't get rid of the last separator so it ends up like : category, category, category,  I tried 'stripping' it (php seriously confuses me small design mind)  foreach((get_the_category()) as $category) {     echo $category-&gt;cat_name . ', ';     echo rtrim($category, ", "); }   That didn't trim it though.
6470
I have code in functions.php:  function string_limit_words($string, $word_limit) {   $words = explode(' ', $string, ($word_limit + 1));   if(count($words) &gt; $word_limit)   array_pop($words);   return implode(' ', $words); }   but i need to limit excerpt in number of characters, could you help me with that?
94609
I'm working at an app which would make a POST ajax request to a PHP script on my server. The script would query the database and return a row of records, as an array. (One array for each row, containing elements such as id, title, etc). I then want to use json_encode() to encode this array, and pass it back to the javascript which will use it to display the records.  1) How can I return the JSON encoded string to the javascript? 2) How will the javascript loop through the rows and access their fields?
28749
I’ve run into a limitation in the cURL bindings for PHP. It appears there is no easy way to send the same multiple values for the same key for postfields. Most of the workarounds I have come across for this have involved creating the URL encoded post fields by hand tag=foo&amp;tag=bar&amp;tag=baz) instead of using the associative array version of CURLOPT_POSTFIELDS.  It seems like a pretty common thing to need to support so I feel like I must have missed something. Is this really the only way to handle multiple values for the same key?  While this workaround might be considered workable (if not really annoying), my main problem is that I need to be able to do multiple values for the same key and also support file upload. As far as I can tell, file upload more or less requires to use the associate arravy version of CURLOPT_POSTFIELDS. So I feel like I am stuck.  I have  about this problem in more detail on the cURL PHP mailing list in the hopes that someone there has some ideas about this.  Suggestions or hints on where I can look for more information on this are greatly appreciated!
6195
Using PHP, what's the fastest way to convert a string like this: "123" to an integer?  Why is that particular method the fastest? What happens if it gets unexpected input, such as "hello" or an array?
4791
Say i have this PHP code:  $FooBar = "a string";   i then need a function like this:  print_var_name($FooBar);   which prints:  FooBar   Any Ideas how to achieve this? Is this even possible in PHP?
44995
I had this question earlier and it was concluded it was a bug in 5.2.5.  Well, it's still broken in 5.2.6, at least for me:  Please let me know if it is broken or works for you:  $obj = new stdClass(); $obj-&gt;{"foo"} = "bar"; $obj-&gt;{"0"} = "zero"; $arr = (array)$obj;  //foo -- bar //0 --    {error: undefined index} foreach ($arr as $key=&gt;$value){     echo "$key -- " . $arr[$key] . "\n"; }   Any ways to "fix" the array after it has been cast from a stdClass?