How can I pass an optional parameter to a PHP function. For example  function test($required, $optional){..}   So that i should be able to call the function by passing either one parameter or both. For example:  test($required, $optional) test($required);   Thanks.
30885
In the PHP manual, to show the syntax for functions with optional parameters, they use brackets around each set of dependent optional parameter. For example, for the  function, the manual reads:  string date ( string $format [, int $timestamp = time() ] )   Where $timestamp is an optional parameter, and when left blank it defaults to the  function's return value.  How do you go about creating optional parameters like this when defining a custom function in PHP?
94051
I want to do something like this:    create table app_users (     app_user_id smallint(6) not null auto_increment primary key,     api_key     char(36) not null default uuid() );    However this results in a error, is there a way to call a function for a default value in mysql?  thanks.
83512
In C can I pass a multidimensional array to a function as a single argument when I don't know what the dimensions of the array are going to be?  Besides, my multidimensional array may contain types other than strings.
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?
5634
I can use set_error_handler() to catch most PHP errors, but it doesn't work for fatal (E_ERROR) errors, such as calling a function that doesn't exist. Is there another way to catch these errors?  I am trying to call mail() for all errors and am running PHP 5.2.3.
76167
I'm not sure if I have done this correctly.  As I understand it:  if I have a class foo and a static method bar I can register that as the callback by passing the array array("foo","bar") as the function name.  If I have an instance of a class in $foo and want to call the method bar I pass the array array($foo,'bar').  If I need to register an action inside the class itself would it work with array($this,'bar')?
213
Why can't I pass the table name to a prepared PDO statement?  $stmt = $dbh-&gt;prepare('SELECT * FROM :table WHERE 1'); if ($stmt-&gt;execute(array(':table' =&gt; 'users'))) {     var_dump($stmt-&gt;fetchAll()); }   Is there another safe way to insert a table name into a SQL query? With safe, I mean that I don't want to do  $sql = "SELECT * FROM $table WHERE 1"
73621
Is there any way to create the query parameters for doing a GET request in JavaScript?  Just like in Python you have , which takes in a dictionary (or list of two tuples) and creates a string like 'var1=value1&amp;var2=value2'.
91767
I've setup a very specific function and it works well but I'd like to make the parameters optional but I can't get a handle on the regex bit:  add_rewrite_rule('whats-on/([^/]+)/([^/]+)/([^/]+)/?$', 'index.php?page_id=71&amp;event_year=$matches[1]&amp;event_month=$matches[2]&amp;event_day=$matches[3]','top');   /whats-on/2012/01/25 I'll show all events on this date.  /whats-on/2012/01 goes to 404 but I'd like the parameter to be optional so I can show all January dates and the same for /whats-on/2012 all dates in year 2012  Any help will gratefully received - thanks
65851
Is there a well-supported, common behavior that I can expect if I do something like this in HTML:  &lt;form method="get" action="/somePage.html?param1=foo&amp;param2=foo"&gt;   &lt;input name="param2"&gt;&lt;/input&gt;   &lt;input name="param3"&gt;&lt;/input&gt; &lt;/form&gt;   Seems like this sort of thing is inherently ridiculous, but I've seen it used here and there and I was wondering what on Earth the expected behavior should be.  Are browsers smart enough to tack on "&amp;param2=whatever&amp;param3=whatever" to the action, or do they just throw in a second question mark?  Or what?  Are there cases where this is actually the right way to do things?
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?
85072
What kind of performance implications are there to consider when using try-catch statements in php 5?   I've read some old and seemingly conflicting information on this subject on the web before. A lot of the framework I currently have to work with was created on php 4 and lacks many of the niceties of php 5. So, I don't have much experience myself in using try-catchs with php.
101805
I am not familiar with PHP at all and had a quick question.  I have 2 variables pricePerUnit and InvoicedUnits. Here's the code that is setting these to values:  $InvoicedUnits = ((string) $InvoiceLineItem-&gt;InvoicedUnits); $pricePerUnit = ((string) $InvoiceLineItem-&gt;PricePerUnit);   If I output this, I get the correct values. Lets say 5000 invoiced units and 1.00 for price.  Now, I need to show the total amount spent. When I multiply these two together it doesn't work (as expected, these are strings).  But I have no clue how to parse/cast/convert variables in PHP.  What should I do?
74983
I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form  mysql_connect($host, $user, $pass) or die("could not connect");   How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen it before.
78348
You can do this in Python, but is it possible in PHP?  &gt;&gt;&gt; def a(): print 1 ...  &gt;&gt;&gt; def a(): print 2 ...  &gt;&gt;&gt; a() 2   e.g.:  &lt;? function var_dump() {} ?&gt; Fatal error: Cannot redeclare var_dump() in /tmp/- on line 1
27417
Using jQuery, how do you check if there is an option selected in a select menu, and if not, assign one of the options as selected.  (The select is generated with a maze of PHP functions in an app I just inherited, so this is a quick fix while I get my head around those :)
54053
Why do PHP regexes have the surrounding delimiters? It seems like it would be more clear if any pattern modifiers were passed in as a parameter to whatever function was being used.