Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://php.net/manual/en/language.pseudo-types.php" rel="nofollow noreferrer">Callbacks</a>, like the one used by usort, can be specified in 3 different ways:</p> <ul> <li><p>a string containing the name of the function: </p> <pre><code>usort($mylist, 'compare_foos'); </code></pre></li> <li><p>an actual function:</p> <pre><code>usort($mylist, create_function(/*...*/)); // php &gt;= 5.3 only: usort($mylist, function ($a, $b) { /* ... */ }); </code></pre></li> <li><p>an array to access object methods:</p> <pre><code>usort($mylist, array($myobject, 'mymethod')); </code></pre></li> </ul> <p>Using a callback the way you did is not valid and php returns an error:</p> <pre><code>PHP Notice: Use of undefined constant compare_foos - assumed 'compare_foos' in /home/lepidosteus/test.php on line 28 </code></pre> <p>To see it, remember to code with every error enabled on your development machine (but hide them on the production server), using <a href="http://php.net/manual/en/function.error-reporting.php" rel="nofollow noreferrer">error_reporting()</a>:</p> <pre><code>error_reporting(E_ALL); // display all errors including notices error_reporting(0); // hide all errors </code></pre> <p>By the way if you want to use an object as a simple store, you don't need to create a dedicated class you can use <a href="https://stackoverflow.com/questions/931407/what-is-stdclass-in-php">stdClass()</a>:</p> <pre><code>$mylist[$i] = new stdClass(); $mylist[$i]-&gt;idx = $i; $mylist[$i]-&gt;data = rand() % 20; </code></pre> <p>Also, you can use <a href="http://fr2.php.net/var_dump" rel="nofollow noreferrer">var_dump()</a> instead of print_r when you debug to get detailed information about the type of each variable, can help you quickly find out if something is wrong.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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