• Resolved ptryk

    (@ptryk)


    getting the error:
    Warning: array_keys(): The first argument should be an array in…

    within a plugin i am editing whereby i am trying to add a sort function called within the plugin.. the sort function code can be found at
    http://se2.php.net/manual/en/function.sort.php
    the function by ” timc at hlyw dot com”

    anyone have any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter ptryk

    (@ptryk)

    just found another sort method, but i am having trouble with the syntax..

    from..
    http://se.php.net/manual/en/function.array-multisort.php
    posted by AlberT at SuperAlberT dot it


    /**
    * orders a multidimentional array on the base of a label-key
    *
    * @param $arr, the array to be ordered
    * @param $l the "label" identifing the field
    * @param $f the ordering function to be used,
    * strnatcasecmp() by default
    * @return TRUE on success, FALSE on failure.
    */
    function array_key_multi_sort(&$arr, $l , $f='strnatcasecmp') {
    return usort($arr, create_function('$a, $b', "return $f(\$a['$l'], \$b['$l']);"));
    }

    just looking for some alternatives if nothing else

    what are you trying to sort? http://pastebin.com

    Thread Starter ptryk

    (@ptryk)

    trying to sort pages w/r/t a “field” .e.g. “menu_order”.. can’t think of any way to do it where it needs to be done..

    got an array that the page data has been read into…eg
    $pagedatacopy
    it is of the form..eg (“.” signify a clip of many fields)

    (
    [0] => stdClass Object
    (
    [ID] => 24
    .
    .
    [menu_order] => 30
    )
    [1] => stdClass Object
    (
    [ID] => 12
    .
    .
    [menu_order] => 10
    )
    [1] => stdClass Object
    (
    [ID] => 31
    .
    .
    [menu_order] => 20
    )
    )

    would like to be able to sort the array so that for example the pages will go through the rest of the processing in the correct order for the correct output .. hope this helps to clarify

    Are you trying to sort arrays of object? You need a custom function for that.

    Try the following or google for “sort objects in php”
    http://us3.php.net/manual/en/function.asort.php#20433

    Thread Starter ptryk

    (@ptryk)

    .. right.. the first one i think i have figured out i mistakenly tried to apply to a multidimensional array.. which i think is what caused the error/warning ..

    the second funciton for using with multidimensional arrays (so it says) i simply can’t seem to get it to go…

    Thread Starter ptryk

    (@ptryk)

    ahhh… figured out another tidbit.. can’t do sorts on “stdClass”‘s .. suck. so what would happen if i were to convert it? .. sort then convert it back? this is getting WAY complicated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Warning: array_keys(): The first argument should be an array in…’ is closed to new replies.