I want to check whether the current year is greater than a date string(D-M-Y) here is my code $OldDate = “09-30-2011”; $OldYear = strtok($OldDate, ‘-‘); $NewYear = date(“Y”); if ($OldYear < $…
Tag: php
Why is array_walk with anonymous function providing different result than foreach?
PHP Version 5.3.2-1ubuntu4.15 1st, starting values: Try this: And get $value_array == (2,4.53,10); But if you run this: You get $value_array == (0,2.53,8); The first one gives the expected result, the second one doesn’t. But it does do SOMEthing. The excess 0’s ended up getting chopped off. Why is…
Sort an array of alphabetic and numeric string-type elements ASC, but with numeric elements after alphabetic elements
I have an array of values which are either all-letters or all-numbers and need to sort them in an ascending fashion. Additionally, I want all-numeric values to be moved to the end of the array so that they occur after all of the non-numeric values. If I run sort() on it I get: but I’d like to see: I tri…
Custom Fonts for DOMPDF
I’m Using DOM PDF 0.6.0 Beta 2. I want to use custom fonts (Fonts: ‘Segeo Print’, ‘Lucida Handwriting’,’Airplanes in the Night Sky’) in PDF file. I followed the guidelines to install and use fonts in my PHP Code, which is given here http://code.google.com/p/dompdf/wik…
PHP rename the keys of an array
How can I rename keys in an array? Start with this array named $start_array, and change the keys for ‘date’ and ‘revenue’ so you get this $final_array: Here is my terrible attempt which works but is messy. Answer Try the above code.
WooCommerce return product object by id
I am creating a custom theme for woocommerce and I need to be able to create a mini product display. I am having problems finding documentation on the woocommerce api. I have a comma delimited list of product IDs that I need to iterate through and display a custom mini product display for each in sequence. An…
codeigniter flatten array of query result
I’m using a query in Codeigniter to return the ids of all the rows that belong to a user. This returns Is it possible to return a flat array like ? Answer The CodeIgniter documentation (most particularly, query results) doesn’t list anything that will produce a flat array result (like the PDO::FET…
PHP multiline string with PHP
I need to echo a lot of PHP and HTML. I already tried the obvious, but it’s not working: How can I do it? Answer You don’t need to output php tags:
Best way to write arrays to a file? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year. Improve this question I want to avoid writing to DB and use constants/array for lang files et…
Insert elements from one array (one-at-a-time) after every second element of another array (un-even zippering)
What would be an elegant way to merge two arrays, such that the resulting array has two items from the first array followed by a single item from the second array, repeating in this fashion? Desired result: I’m trying to do it using a for loop with multiple counters, but I don’t know that the arra…