Difference between mysql_connect() and mysql_pconnect()?
In shortly mysql_pconnect() makes a persistent connection to the database which do not close when the execution of your script ends
In shortly mysql_pconnect() makes a persistent connection to the database which do not close when the execution of your script ends
$myworld = array("a"=>"PHP","b"=>"learning","c"=>"I'm");
krsort($myworld);
print_r($myworld);
?>
In PHP you will, in most cases, be able to get by with one of the default sort functions, perhaps used in conjunction with each other.
$inputwords = array("whichever","word","is","the","longest","will","appear","at","the","top");
usort($inputwords, "sortlen");
print_r($inputwords);
function sortlen($a,$b) {
$lena = strlen($a); $lenb = strlen($b);
if ($lena == $lenb) return 0;
return ($lena > $lenb) ? -1 : 1;
}
?>
$inputwords = array("whichever","word","is","the","shortest","will","appear","at","the","top");
usort($inputwords, "sortlen");
print_r($inputwords);
function sortlen($a,$b) {
$lena = strlen($a); $lenb = strlen($b);
if ($lena == $lenb) return 0;
return ($lena < $lenb) ? -1 : 1;
}
?>
Sometimes if you are moving through the various elements in array, you will want to return the pointer to beginning of the array.
$numbers = array("Item 1","Item 2","Item 3");
next($numbers);
$thisvalue = current($numbers); echo "We are now at $thisvalue\n\n";
$first = reset($numbers);
echo "Back to $first";
?>
If you wish to check whether a value is already stored in an array or not, then use the in_array function.
$values = array("banana","apple","pear","banana");
$newvalue = "pear";
if (in_array($newvalue,$values)) { echo "$newvalue is already in the array!"; }
?>