Hi all,i tried to do some research regarding associated arrays in php,even manual on the php documentations,but can not find the answer,how do i print the smallest value and the associated key from the array?

Recommended Answers

All 3 Replies

Member Avatar for diafol

Quick n dirty:

$array = ['me'=>10,'you'=>9, 'them'=>33];
asort($array);
$key = key($array);
$val = $array[$key];

echo "The key is '$key' and the value is '$val'";

Thank you. Just a quck question why is it lousy?Is the any other ways to do it?

Member Avatar for diafol

Didn.t say lousy. Just said quick n dirty meaning in this instance that I just cobbled it.together quickly without thinking too much about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.