I have loaded an array with the results of a database Have fun tweaking this )) i know you will )) each array in the $attrib is a product :P) if you want to sort only the uniq results use the above or use this: Each array in the $attrib array consists in multiple fields (ex: name, lenght, price, etc.) to be more simpler in speech think that $attrib is the array resulted by a search sql query done by a visitator on your online shoopping website. my problem was multidimensional sort.Īrray $attribs is an array contaning arrays. $res4 = array_keys ( array_flip ( $arr )) Įcho "deduped to ". $res2 = array_flip ( array_flip ( $arr )) Įcho "deduped to ". The array_keys(array_flip()) is the fastest method to remove duplication values from a single dimension array:ĭeduped to ". P.S.: in my - practical - case of DB querying I got around 4k uniques and 15k dupes :)Īs for PHP 7.1.12, this is the comparison between array_keys(array_flip()), array_flip(array_flip()), for each elimination and array_unique. Plus - as a bonus - you also get an array of UNIQUE keys you searched for (just uncomment >$key_array Personally I just echo-ed 1st and then 2nd (both DOUBLE COMMENTED) list in function itself (then copied both to notepad++ and compared them - just to be 100% sure), but in case you want to do something else with it - enjoy :) So you can take both and compare them (I had to).Įxample array (copy-paste from original post): I added second return value - array of duplicates. Removed completely (imo was waste of keystrokes anyway).Ģ. In php 7.4 counter $i breaks the function. Modified code originally posted by Ghanshyam Katriya(anshkatriya at gmail). Now, call this function anywhere from your code, You can make it unique for any field like id, name or num. Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto searchĬreate multidimensional array unique for any single key index.Į.g I want to create multi dimentional unique array for specific code
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |