Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>output:</p> <p><img src="https://i.stack.imgur.com/y3abv.png" alt="output"> source:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;?php $nouns = array ( "data" =&gt; array("data"), "datum" =&gt; array("data"), "man" =&gt; array("men"), "octopus" =&gt; array("octopi", "octopuses"), "ox" =&gt; array("oxen"), "hippopotamus" =&gt; array("hippopotami", "hippopotamuses") ); function find_singular($nouns, $search) { foreach($nouns as $noun =&gt; $values) { if(in_array($search, $values)) { $found[] = $noun; } } if(!empty($found)) { $n = count($found); if($n &gt; 1) { echo "&lt;strong&gt;$search&lt;/strong&gt; has $n singular forms: &lt;em&gt;"; print_r(implode('&lt;/em&gt; and &lt;em&gt;', $found).'&lt;/em&gt;&lt;br /&gt;'); } else { echo "&lt;b&gt;$search&lt;/b&gt; is the plural of &lt;em&gt;$found[0]&lt;/em&gt;&lt;br /&gt;"; } } else { echo "&lt;b&gt;$search&lt;/b&gt; was not found.&lt;br /&gt;"; } } find_singular($nouns, "men"); find_singular($nouns, "octopi"); find_singular($nouns, "data"); find_singular($nouns, "oxen"); find_singular($nouns, "octopuses"); find_singular($nouns, "hippopotami"); find_singular($nouns, "kittens"); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>hope this helps!</p> <p>EDIT: what is the purpose of this? I am guessing you are creating a dictionary application for a web or app interface. I don't think you're going to be able to avoid loops so long as you intend on implementing a search ability. are you storing the whole dictionary in a PHP array? I assume you are since XML and mysql queries would cost even more time. my only other suggestion would be to split the dictionary into as many arrays you can manage (perhaps a few dozen per alphabetic letter) else write a script to produce these from either the existing dictionary array or a flat file, and then implement AJAX in your search box, similar to Google's predictive search but instead of displaying possible results as the search string is typed, it would be narrowing down which array to search, silently in the background. I have a script somewhere which does this and can dig it up if this sounds viable. basically, instead of searching the whole dictionary (I have seen one with in excess of twelve million words!) per keyword, by the time the keyword is typed, sent and processed, there could be much fewer loop cycles. hardware also springs to mind - the hard disk, processor and memory speeds of the server will account for most of the equation. I have also heard that C++ is much more suited to dictionary searches and would not be too foreign an option for a PHP developer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload