PHP - Adding A Add And Remove Function For A Product Category.
The web application should allow the user to view the items in a catalogue, add items to a shopping cart, remove items from the shopping cart, and to view the contents of the shopping cart.
Hey guys. Right ill try explain as best i can. Basicly we were told to write a php script that can view a shopping cart. The items in the catalogue should be stored as an array of objects. (The next assignment will require you to store this list of objects in a database). There should also be pages to allow the user to add, edit and delete items in the catalogue. Thats taken from a brief.Ive spent the most of the week getting it to view a catalog and now it can add items.view the cart its added them to and remove them from the cart and return. What im having trouble with is making the add function for the the other users or admin* to add/edit/delete.i reckoned adding and deleting wouldnt be so bad considering ive alrready done so.But im kinda stumped on how to do it.i think what the brief wanted was a seprate product add that would actully let u add another product to the cart list on the same page and then u can add that to the shopping basket etc. Yea real stumped.if only it was through sql it would be so much handier. ill post the code below.if anyone can help at all in the slightest id be so grateful.Thank you. Similar TutorialsI'm trying to make one big array with my websites menu that has the categorys and the products i'm using code i found at http://www.phpfreaks.com/forums/index.php?topic=326419.msg1536842#msg1536842 its working fine till i try get the sub category and its products into the array $cats = array( 0 => array( 'categoryID' => 1, 'name' => 'Menu', 'parent' => 0) ,1 => array( 'categoryID' => 50, 'name' => 'Takeaway', 'parent' => 60) ); //root of the category $categorys = array( 1 => array( 1 => array( 'categoryID' => 6 , 'name' => 'Breads' , 'parent' => 1 ) ,0 => array( 'categoryID' => 2 , 'name' => 'Drinks' , 'parent' => 1 ) ,2 => array( 'categoryID' => 7 , 'name' => 'Salads' , 'parent' => 1 ) ) ,2 => array( 0 => array( 'categoryID' => 4 , 'name' => 'Tea' , 'parent' => 2 ) ,1 => array( 'categoryID' => 18 , 'name' => 'Coffee' , 'parent' => 2 ) ) ); // the category themselfs $product = array(6 => array( 0 => array('productID' => 1, 'categoryID' => 6,'name' => 'Plain Bread', 'description' => 'description') ,1 => array('productID' => 2, 'categoryID' => 6, 'name' => 'Garlic Bread', 'description' => 'description') ) ,7 => array( 0 => array('productID' => 44, 'categoryID' => 7, 'name' => 'Garden Salad', 'description' => 'description') ,1 => array('productID' => 45, 'categoryID' => 7, 'name' => 'Greek Salad', 'description' => 'description') ) ,4 => array( 0 => array('productID' => 74, 'categoryID' => 4, 'name' => 'Green Tea', 'description' => 'description') ) ,18 => array( 0 => array('productID' => 75, 'categoryID' => 18, 'name' => 'Espresso', 'description' => 'description') ) ); // the products if(is_array($cats)) { foreach($cats as $cat) { if(is_array($categorys[$cat['categoryID']])) { foreach($categorys[$cat['categoryID']] as $category) { if(is_array($categorys[$category['categoryID']])) { foreach ($categorys[$category['categoryID']] as $subcat){ $subcat['product'] = $product[$subcat['categoryID']]; $subprod[] = $subcat; //have tryed using parent $subprod[$subcat['parent']] but it over rides it self each time } } $category['product'] = $product[$category['categoryID']]; $category['subcategory'] = $subprod; // here is where I'm having problem $this_category[] = $category; } } if(!empty($this_category)){ $ncategory[] = array($cat,$this_category); } $this_category = array(); } } print_r($ncategory); thank you for your time sorry for any spelling or grammar errors I'm working on a business listing website using a Wordpress theme as the framework. Unfortunately, there is a limited number of categories with no option for a user to request a category. Below you can see an image of the form that users utilize to create a listing. http://postimg.org/image/5r8scqh8f/ Here is the relevant code related to that section: function aitDirItemTaxonomies() { register_taxonomy( 'ait-dir-item-category', array( 'ait-dir-item' ), array( 'hierarchical' => true, 'labels' => array( 'name' => 'Item Categories', 'singular_name' => _x( 'Category', 'taxonomy singular name', 'ait'), 'search_items' => __( 'Search Category', 'ait'), 'all_items' => __( 'All Categories', 'ait'), 'parent_item' => __( 'Parent Category', 'ait'), 'parent_item_colon' => __( 'Parent Category:', 'ait'), 'edit_item' => __( 'Edit Category', 'ait'), 'update_item' => __( 'Update Category', 'ait'), 'add_new_item' => __( 'Add New Category', 'ait'), 'new_item_name' => __( 'New Category Name', 'ait'), ), 'show_ui' => true, 'rewrite' => array( 'slug' => 'cat' ), 'capabilities' => array( 'assign_terms' => 'assign_dir_category' ) )); register_taxonomy( 'ait-dir-item-location', array( 'ait-dir-item' ), array( 'hierarchical' => true, 'labels' => array( 'name' => 'Item Locations', 'singular_name' => _x( 'Location', 'taxonomy singular name', 'ait'), 'search_items' => __( 'Search Location', 'ait'), 'all_items' => __( 'All Locations', 'ait'), 'parent_item' => __( 'Parent Location', 'ait'), 'parent_item_colon' => __( 'Parent Location:', 'ait'), 'edit_item' => __( 'Edit Location', 'ait'), 'update_item' => __( 'Update Location', 'ait'), 'add_new_item' => __( 'Add New Location', 'ait'), 'new_item_name' => __( 'New Location Name', 'ait'), ), 'show_ui' => true, 'rewrite' => array( 'slug' => 'loc' ), 'capabilities' => array( 'assign_terms' => 'assign_dir_location' ) )); } add_action( 'init', 'aitDirItemPostType');Website: http://reliablist.com I have made multiple attempts to try to create a 'Request a Category' button, but unfortunately have been defeated by my lack of experience. If I could get help in any direction, it would be greatly appreciated. Hi there, I've been trying to implement pagination to an existing script that displays products, but at present only displays next and back buttons. The number of products is now increasing and we would like to show the number of pages of results but the tutorials I've been going through seem to use a very different way of displaying the results to the script we currently have. Does anyone have any suggestions how I could add pagination to this form..... // Build Pagination $ByPage = ($prod_rows * $prod_cols); $qnav = "SELECT devbg_products.*, devbg_categories.*, devbg_subcategories.* FROM devbg_products LEFT JOIN devbg_categories ON devbg_products.ItemCategory = devbg_categories.CategoryID LEFT JOIN devbg_subcategories ON devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID WHERE devbg_products.ItemCategory = " . sql($cgid); $rnav = mysql_query($qnav) or die(mysql_error()); $rows = mysql_num_rows($rnav); if($rows > $ByPage) { $pages = ceil ($rows / $ByPage); echo "<br>\n"; echo "<table align='center'>\n"; echo "<tr>\n"; echo "<td align=center><font face=verdana size=2>"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start - $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if (($Start - $ByPage) <> -$ByPage) { echo "<input class='sub' type='submit' value='<<< Back' name='btnBack'>\n"; echo "</form>\n"; echo "</td>\n"; } echo "<td>\n"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start + $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if ($Start + $ByPage < $pages * $ByPage) { echo "<input class='sub' type='submit' value='Next >>>' name='btnNext'>"; } echo "</form>\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table><br><br>\n"; } This is the code that I'm using for a shopping cart in order to update the quantity if the same product id is chosen. $cart_items is a two-dimensional session array composed of the id session array and the quantity session array. While looping through $cart_items, I create a temporary array $temp_array so that I can execute some logic on the array without changing the normal output. $temp_array is the $cart_items array without the last items which would be the $_REQUEST id and the $_REQUEST quantity. So the two $_REQUESTs are popped off with array_pop and then the remaining $_SESSIONs are compared to the $_REQUEST id with
$j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) If $j is the key of the item in $temp_array, then the $_REQUEST is unset and the quantities for the item are added together.
There are two problems with this code. First of all the var_dump of the $temp_array is always an empty array but I am expecting to get an array with just the last element popped off. Secondly, foreach($cart_items as $item) { foreach($item["id"] as $key => $val) { foreach($item["quantity"] as $i => $value) { if ($key == $i){ $temp_array = $cart_items; $array = array_pop($temp_array); var_dump($temp_array); if (isset($_REQUEST["element_id_$i"]) && isset($_REQUEST["quantity_$i"])&& isset($value)){ $j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) { echo "<b>SAME PRODUCT ADDED</b>"; $value += $_REQUEST["quantity_$i"]; unset($_REQUEST["element_id_$i"]); }}}}}}
Hello everyone, I am currently working on the script taken from www.phpwebcommerce.com I am only a beginner and have been using it in a little project for an online game just to help my mates be able to trade items and such. I have managed to get almost everything sorted apart from one thing. The function which gets the categories for a drop down select box: Code: [Select] /* Generate combo box options containing the categories we have. if $catId is set then that category is selected */ function buildCategoryOptions($catId = 0) { $sql = "SELECT cat_id, cat_parent_id, cat_name FROM tbl_category ORDER BY cat_id"; $result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error()); $categories = array(); while($row = dbFetchArray($result)) { list($id, $parentId, $name) = $row; if ($parentId == 0) { // we create a new array for each top level categories $categories[$id] = array('name' => $name, 'children' => array()); } else { // the child categories are put int the parent category's array $categories[$parentId]['children'][] = array('id' => $id, 'name' => $name); } } // build combo box options $list = ''; foreach ($categories as $key => $value) { $name = $value['name']; $children = $value['children']; $list .= "<optgroup label=\"$name\">"; foreach ($children as $child) { $list .= "<option value=\"{$child['id']}\""; if ($child['id'] == $catId) { $list.= " selected"; } $list .= ">{$child['name']}</option>\r\n"; } $list .= "</optgroup>"; } return $list; } Basically the problem is that it only creates a category list of two levels e.g. Parent Child and I wish to be able to have more sub categories e.g. Parent Child Child Child Is there anyway of adapting this code so it can do something like that? Many thanks for any help. Since I'm new to programming I still don't know how to solve problems the most efficient way, I'd like to have your advice on this one. This is how I solved it and it works. I have my categories as input buttons (I'm planning to change it into a drop down menu later). Sort by Category: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type='submit' name='All' value='All' /> <input type='submit' name='Smileys' value='Smileys' /> <input type='submit' name='Faces' value='Faces' /> <input type='submit' name='Love' value='Love' /> </form> When the input boxes are clicked the corresponding script below is being run, very simple and to a point primitive, definitely not really efficient, because if you have a lot of categories you'll end up with a lot of code and if you wanted to change one thing you'd have to change it in all the IF BLOCKS. Basically every input button has its own IF BLOCK. <?php if (isset($_POST['All']) OR (!isset($_POST['Smileys']) && !isset($_POST['Faces']) && !isset($_POST['Love']) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the score data from MySQL $query = "SELECT * FROM asciiart"; $data = mysqli_query($dbc, $query); // Loop through the array of score data, formatting it as HTML while ($row = mysqli_fetch_array($data)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } if (isset($_POST['Smileys'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query2 = "SELECT * FROM asciiart WHERE asciiart_category = 'Smileys'"; $data2 = mysqli_query($dbc, $query2); //Loop through the array of data while ($row2 = mysqli_fetch_array($data2)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row2['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row2['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row2['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row2['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } if (isset($_POST['Faces'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query3 = "SELECT * FROM asciiart WHERE asciiart_category = 'Faces'"; $data3 = mysqli_query($dbc, $query3); //Loop through the array of data while ($row3 = mysqli_fetch_array($data3)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row3['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row3['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row3['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row3['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } if (isset($_POST['Love'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query4 = "SELECT * FROM asciiart WHERE asciiart_category = 'Love'"; $data4 = mysqli_query($dbc, $query4); //Loop through the array of data while ($row4 = mysqli_fetch_array($data4)) { echo '<table class="asciiartTable">'; // Display the score data echo '<tr><td class="asciiart_name">'; echo '<strong>' . htmlentities($row4['asciiart_name']) . '</strong><br /></td></tr>'; echo '<tr><td class="asciiart_contribution"><pre>' . htmlentities($row4['asciiart_contribution']) . '</pre><br /></td></tr>'; echo '<tr><td class="asciiart_categoryDate">' . htmlentities($row4['asciiart_category']) . ' | ' . date('M d, Y', strtotime ($row4['created_date'])) . ' </td></tr>'; echo '</table>'; } mysqli_close($dbc); } My question is: is there a way to have just one block of script and the script automatically inserts the right INPUT BUTTON into the query in the script? Something similar to this, even though it doesn't work I'm just showing it for showcase purposes: if (isset($_POST['Smileys']) || (isset($_POST['Faces']) || (isset($_POST['Love'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the chosen category from MySQL $query2 = "SELECT * FROM asciiart WHERE asciiart_category = 'Smileys' || 'Faces' || 'Love'"; $data2 = mysqli_query($dbc, $query2); Notice in the query, it is looking for THAT keyword that has been PRESSED on the INPUT BUTTON. How would I be able to create a logic like this so I can create a whole chain of categories? Thanks for advice. Hello, I have been searching and trying all sorts of ways to get my sub categories drop down to show the correct info after selecting a category from the main drop down but im getting stuck. It's pulling the categories and sub categories from the mysql database fine but no matter which main category i pick it keeps showing the same result in the sub category. My brother said i need to use some sort of onchange do this so the sub category list refreshs but everything i have tried doesn't work.. PLEASE could some one help. MANY MANY THANKS This is the category form Code: [Select] <select name="job_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_cats"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $job_cats_title1 = $row1['title']; $job_cats_id1 = $row1['id']; echo '<option value="'.$job_cats_id1.'">'.$job_cats_title1.'</option>'; echo $job_cats_id1; } ?> </select> this would echo this in the main category list: cat1 cat2 cat3 cat4 this is the sub category form Code: [Select] <select name="job_sub_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_sub_cats WHERE job_cats_id = $job_cats_id1"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $sub_cats_id1 = $row1['id']; $sub_cats_title1 = $row1['subTitle']; $cats_id1 = $row1['job_cats_id']; echo '<option value="'.$sub_cats_id1.'">'.$cats_id1.'</option>'; } ?> </select> this should echo this: 1 2 3 4 but it keeps echoing just the number 4. THANKS PLEASE HELP ricky hello all, i have a small problem. i have a bunch of prices in a database like 243.49 and 1,256.22 etc. the problem is that when i try to add multiple prices that one of the fields is over 1000, it is treating it as 1 (i believe because of the comma.) is there a way to remove the comma, but not the decimal if it exists and then add it back to the $total if it is over 1000? Code: [Select] $pamount=$row2['amount']; $total += $pamount; Hi there, I'm trying to get the full Product Name in the <title> of each of the product pages - I can't seem to figure out what to put in the product_info.php... I've tried a few different options but I'm not great with php Here's what I have currently but it creates errors... <script language="javascript"><!-- document.write('<title><?php echo TITLE; ?> : <?php echo $product_info['products_name']; ?> </title>'); //--></script> Hope someone can help - thanks so much! I have sen this function before but can not remember what it is or how to code it. It allows you remove only defined characters from the end of the string. I am not looking to replace any occurrence anywhere in the phrase, just the end. For example lets say I want to remove"ld!" from phrase "Hello World!" That function would return "Hello Wor" Thanks I'm using the codeigniter mvc framework and there's an escape function to use before adding the data to the database. This function adds single quotes around the string of data. Is there any already existing php function or does anyone know how to code a function that strips ONLY the surrounding single quotes? Hello, I am puzzled as to how to get this code actually working, I am using some example code, I want the code to remove the data of the logged in users, at the moment it will remove all users registered in the mysql db. <?php # Access session. session_start() ; if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; } # Connect to the database. require ('connect_db.php'); // Attempt delete query execution $sql = "DELETE FROM users WHERE user_id=user_id"; if(mysqli_query($dbc, $sql, $q)){ echo "Records were deleted successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($dbc); } # Close database connection. mysqli_close( $dbc ) ; ?> $_session id knows that the user is logged into the control page, but for the code to remove the particular user logged in from the db, what exactly does this need? Thank you. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=322184.0 I've added a CSS class to the main menu of a Wordpress site and wish to remove the class if the browser width drops below a certain number. I've tried a number of different approaches but none has worked.
Some examples:
$(document).ready(function() { Hi, i got help earlier with the this code-- exploding a field and getting an array, then inserting the array into a multiselect box-- That part is easy and works fine. Now the explode function gives an array of words with duplicate words in it: I tried several ways most either give a blank option/value, or the array word.. here is the code: $query = "SELECT DISTINCT property_functionsexperience FROM #__users_profiles WHERE published = '1' ORDER BY property_functionsexperience ASC"; $functionsexperiencelistgeneral=doSelectSql($query); foreach($functionsexperiencelistgeneral as $words) $property_funcexperilist=$words->property_functionsexperience; $wording = explode(', ', $property_funcexperilist); foreach($wording as $funciex) $funcexi=array_unique($funciex); $funcexpList .= "<option value=\"".$funcexi.','."\">".$funcexi."</option>"; $funcexpList .= "</optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; this code is adapted slightly from the working original that gives the double words-- this code gives a blank, but i think its on the correct track!? Hi im having some trouble when i try to add values to an array from a function. The added value will not stay saved. fun1 will display both firstname and surname but when i call fun2 after calling fun1 i just get the firstname. I would like to have it so the array is updated and stays updated untill it is cleared or over written. Any help with this would be greatly appreciated. i am using codeigniter if that makes any difference. Thanks <?php class Test extends Controller { var $data1 = array( 'firstname' => 'craig' ); function fun1() { global $data1; $this->data1['surname'] = 'brute'; echo "<pre>"; print_r($this->data1); } function fun2() { global $data1; echo "<pre>"; print_r($this->data1); } } I made a function which displays the left and right children of the root. However i need to add serial numbers to them. Due to Recursive functions i'm not quite able to to do so . Can someone please help me? Code: [Select] function side_display($root) { $sql = "SELECT lchild,rchild FROM tree WHERE parent='".$root."'"; $sqlexec = mysql_query($sql); $array = mysql_fetch_array($sqlexec); if(!empty($array['lchild']) && $array['lchild'] != '0') { echo "<tr>"; echo "<td>".($array['lchild'])."</td>"; $get = "SELECT * FROM member WHERE member_id='".$array['lchild']."'"; $execget = mysql_query($get); $getarray = mysql_fetch_array($execget); echo "<td>".$getarray['fname']." ".$getarray['lname']."</td>"; echo "<td>".$getarray['id_sponsor']."</td>" ; echo "<td>Left</td>"; echo "<td>".$getarray['doj']."</td>" ; echo "</tr>"; side_display($array['lchild']); } if(!empty($array['rchild']) && $array['rchild'] != '0') { echo "<tr>"; echo "<td>".($array['rchild'])."</td>"; $get = "SELECT * FROM member WHERE member_id='".$array['rchild']."'"; $execget = mysql_query($get); $getarray = mysql_fetch_array($execget); echo "<td>".$getarray['fname']." ".$getarray['lname']."</td>"; echo "<td>".$getarray['id_sponsor']."</td>" ; echo "<td>Right</td>"; echo "<td>".$getarray['doj']."</td>" ; echo "</tr>"; side_display($array['rchild']); } } Hi all. I try to adding checkbox when I call my function, my Class code is Code: [Select] class SQLconn{ function fetchData($table_name, $argument, $linebreak, $end_linebreak){ $result = mysql_query("select * from $table_name where status='$argument'"); while($row=mysql_fetch_row($result)){ echo $linebreak.$row[1]."<input type='checkbox' name='option' id='checkbox' value=$row[0] />".$end_linebreak; //$row[0] is 'job_id' from database } } } and my view code is like this Code: [Select] <?php $connect = new SQLconn(config()); $connect->connectDB(); $connect->fetchData("todo", "Undone", "<li>", "</li>"); //this is where the problem is $connect->closeConn(); ?> With that code I succesfully achieve my goal to add checkbox with right 'job_id' value but this is a workaround and not good because if I code it this way my function will be broken if use it somewhere else. My question is, how can I fix my code so I can add checkbox to view page but I can keep my function clean? Really need opinion about this?? I cant figure out how to add $recieved into this needs to take place of time hope someone knows how to do this what im doing is adding in the UNIX time i want to offset Code: [Select] <?php $offset = date('m/d/Y/H:i:s', time()+$send1['time_offset']); ?> This would seem like a simple question, but I can't seem to find the answer anywhere. Perhaps I'm asking it wrong. What I'd like to do is add a hash of optional arguments for a function. For example, I might have a function that has two required arguments, and three optional arguments. The only way I know to design this function is to put the arguments in a specific order, and fill them out to the degree needed. So if the 5th argument needs to be called, but the 3rd and 4th don't, you'd still have to give them values. function example($arg1, $arg2, $arg3, $arg4, $arg5) Must be used by: example('red', 'horse', '', '', 'texas'); Is there anyway of designing a function to only use the specified arguments? example('red', 'horse', ['arg5: texas']); |