Skip to content
Advertisement

Tag: arrays

Combine two arrays

I have two arrays like this: I want to combine these two array such that it does not contains duplicate and as well as keep their original keys. For example output should be: I have tried this but it is changing their original keys: Any solution? Answer Just use: That should solve it. Because you use string keys if one

Using an array as needles in strpos

How do you use the strpos for an array of needles when searching a string? For example: $find_letters = array(‘a’, ‘c’, ‘d’); $string = ‘abcdefg’; if(strpos($string, $find_letters) !== false) { …

PHP loop through months array

This should be easy but I’m having trouble… In PHP how can I echo out a select drop down box that defaults to the current month and has options for 8 months prior (even if it goes in the last year). For example, for this month it would default to June and end at November. Answer Alternative for “custom” month

Search for highest key/index in an array

How can I get the highest key/index in an array with php? I know how to do it for the values. E.g.: from this array I would like to get 10 as an integer value: I know how I could code it but I was asking myself if there is a function for this as well. Answer This should work

Are numeric and associative arrays in PHP two different things?

This is a deeper dive into a previous question I had here: Can items in PHP associative arrays not be accessed numerically (i.e. by index)? According to W3Schools, : In PHP, there are three kind of arrays: Numeric array – An array with a numeric index Associative array – An array where each ID key is associated with a value

Permutations of an array of arrays of strings

I simply cannot wrap my head around how to solve this problem and after a thorough search on Google with no results, I turn to you with hopes of a solution. Given the sample array below: (Note: This is merely a sample; the actual real life situation might have less/more groups and/or elements per group) How would I go about

“Function split() is deprecated” in PHP?

Deprecated: Function split() is deprecated in C:wampwwwRSS.php on line 27 Why this error happen ? Answer http://php.net/manual/en/function.split.php From the manual Warning This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED

How to create an empty array in PHP with predefined size?

I am creating a new array in a for loop. PHP keeps complaining about the offset since for each iteration I add a new index for the array, which is kind of stupid. Is there some way to predefine the number items in the array so that PHP will not show this notice? In other words, can I predefine the

Advertisement