PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pedroz
Forum Commoner
Posts: 99 Joined: Thu Nov 03, 2005 6:21 am
Post
by pedroz » Sun Mar 05, 2006 12:47 pm
I want to display the max strlen word in the following string:
$array_strlen = "02 10dd 6abcd 8ss";
Code: Select all
$array_strlen = "02 10ff 6fffd 8ss";
$array_strlen = array_unique(explode(' ',$array_strlen));
$array_strlen = array_map('strlen', $array_strlen);
$array_strlen = rsort($array_strlen);
echo $array_strlen[0];
What's wrong ? It "should" display
5 ...
Last edited by
pedroz on Sun Mar 05, 2006 1:11 pm, edited 1 time in total.
ambivalent
Forum Contributor
Posts: 173 Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON
Post
by ambivalent » Sun Mar 05, 2006 1:11 pm
Put this right before your last echo:
pedroz
Forum Commoner
Posts: 99 Joined: Thu Nov 03, 2005 6:21 am
Post
by pedroz » Sun Mar 05, 2006 1:18 pm
Nop... It displays 1.
It might be good to rest for a while after several hours without sleepin
ambivalent
Forum Contributor
Posts: 173 Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON
Post
by ambivalent » Sun Mar 05, 2006 1:25 pm
pedroz wrote: Nop... It displays 1.
Then something is not right.
The manual wrote: Possible values for the returned string are:
"boolean" (since PHP 4)
"integer"
"double" (for historical reasons "double" is returned in case of a float, and not simply "float")
"string"
"array"
"object"
"resource" (since PHP 4)
"NULL" (since PHP 4)
"user function" (PHP 3 only, deprecated)
"unknown type"
I get "boolean" when I run the code you posted.
pedroz
Forum Commoner
Posts: 99 Joined: Thu Nov 03, 2005 6:21 am
Post
by pedroz » Sun Mar 05, 2006 1:28 pm
Right...
rsort($array_strlen);
instead
$array_strlen = rsort($array_strlen);
because rsort is boolean function
ambivalent
Forum Contributor
Posts: 173 Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON
Post
by ambivalent » Sun Mar 05, 2006 1:46 pm
Therefore, you don't have an array yet you are trying to output an array element?
Code: Select all
echo "<pre>";
print_r($array_strlen); //prints "1"
echo "</pre>";
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Mar 05, 2006 1:48 pm
Code: Select all
$array_strlen = "02 10ff 6fffd 8ss";
$array_strlen = array_unique(explode(' ',$array_strlen));
$array_strlen = array_map('strlen', $array_strlen);
rsort($array_strlen);
echo $array_strlen[0];
Check the rsort function, it "Returns TRUE on success or FALSE on failure."