本文整理汇总了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