本文整理匯總了PHP中H::each_pair方法的典型用法代碼示例。如果您正苦於以下問題:PHP H::each_pair方法的具體用法?PHP H::each_pair怎麽用?PHP H::each_pair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類H
的用法示例。
在下文中一共展示了H::each_pair方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: quicksort
# the H() function does not accept the KEY => VALUE syntax, but instead accepts a parameter list of alternating KEY, VALUE, parameters
# the new H(array(...)) syntax does accept KEY => VALUE notation but with the drawback that KEYs must be defined using native types.
$h = H(S("SATURN"), 1, 'hello', 2, 'goodbye', 3, 'fatty', 0);
$h = new H(array("SATURN" => 1, 'hello' => 2, 'goodbye' => 3, 'fatty' => 0));
echo "hash = ".$h."\n";
# the each() iterator for hashes pass a 2-pair array containing at offset 0 the KEY and offset 1 the VALUE i.e. A($key, $value)
$h->each(function($x) { echo ">> each() $x <<\n"; });
# the each_pair() function is an alias of each_with_index() passing each key,value pair to the callback function
$h->each_pair(function($x,$y) { echo ">> each_pair() key={$x} value={$y} <<\n"; });
# there are many other methods
# please refer to the code within the lib/ directory for now
# each class is broken up into seperate files
function quicksort($xs) {
if($xs->count() < 2)
return $xs;
$p = $xs->head();
$fn = function($x) use($p) { return $x < $p; };
return