Skip to content
Advertisement

Tag: arrays

How to detect duplicate values in PHP array?

I am working with a one dimensional array in PHP. I would like to detect the presence of duplicate values, then count the number of duplicate values and out put the results. For example, given the following array: I would like to print: Any advice on how to approach this problem? Thanks. Mike Answer You can use array_count_values function will

PHP recursive search and replace array elements

I want to recursively search and replace elements in an array. The array is tree based so looks like etc. I want to be able to replace certain items with other items, so for example, I want to replace all entries in the array (at whatever depth level) of type A with an array of type B. But here’s the

How to bind mysqli parameters using loop and store results in array?

The code above gets the value from genreID when dbGenre is equal to $genre. And then store the results in an array. But it’s not working because $genre is an array, so I need to loop through it to get a different value from genreID each time. The ‘genres’ table contains two columns: genreID (INT) and dbGenre (VARCHAR) I just

Convert a String to Variable

I’ve got a multidimensional associative array which includes an elements like I’ve got a strings like: How can I convert the strings into a variable to access the proper array element? This method will need to work across any array at any of the dimensions. Answer Quick and dirty: Of course the input string would need to be be sanitized

Advertisement