php配列学習ノート


list

$arr = array("apq", "28");
list($name, $age) = $arr;
printf("Name: %s, Age: %s <br />", $name, $age);

stack

function stack_initialize() {
	$new = array();
	return $new;
}

function stack_push(&$stack, $value) {
	$stack[] = $value;
}

//        
function stack_pop(&$stack) {   
    return array_pop($stack);   
}

function stack_peek(&$stack) {   
    return $stack[count($stack)-1];   
}

function stack_size(&$stack) {   
    return count($stack);   
}

function stack_is_empty(&$stack) {
	return count($stack) == 0;
}

$mystack = stack_initialize();
stack_push($mystack, "A");   
stack_push($mystack, "B");
stack_push($mystack, "C");  

while (!stack_is_empty($mystack)) {
	echo stack_pop($mystack) . "<br />";
}