Question

I'm getting an error message Warning: implode(): Invalid arguments passed in

I want to sort the properties here...

Super easy but not working yet... minor tweak needed here :

$css = <<<EOF

z-index : 9;
padding: 0;
margin: 0;
line-height: 10px;

EOF;

echo implode ( ';', ( sort ( explode( ';' , $css ) ) ) );

/* Expecting to get :

line-height: 10px;
margin: 0;
padding: 0;
z-index : 9;

*/

Pretty much self explanatory :)...

Small tweak would make this work :)

Était-ce utile?

La solution

The sort function returns a bool. Also, exploding / imploding on ';' won't give you quite what you want. Try using "\n" instead:

$arr = explode( "\n" , $css );
sort($arr);
echo implode ( "\n", $arr );

If you want to do this all in one line you can write a custom function, like this:

function my_sort($arr) {
    sort($arr);
    return $arr;
}

And then you can call it like this:

echo implode ( "\n", my_sort( explode( "\n" , $css ) ) );
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top